将html标记转换为JavaScript兼容字符串的C#方法
我认为应该存在一种已知的方法来转换:将html标记转换为JavaScript兼容字符串的C#方法,c#,javascript,jquery,html,C#,Javascript,Jquery,Html,我认为应该存在一种已知的方法来转换: <div class="singlePane pane"> <div class="tripleColumn"> <!-- TODO: --> <div class="col"> <div class="captionedLink"> <div class="icon" style="background-position: -26px 0px;
<div class="singlePane pane">
<div class="tripleColumn"> <!-- TODO: -->
<div class="col">
<div class="captionedLink">
<div class="icon" style="background-position: -26px 0px;"> blah blah
请,请告诉我
提前谢谢 这绝不是最快的方法(静态
Regex.Replace
方法比Regex实例慢。但我这样做是为了将任何html转换为可用于文档的字符串。编写:
string htmlResult = "/*string*/";
htmlResult = Regex.Replace(htmlResult, @"\r\n", " ");
htmlResult = Regex.Replace(htmlResult, @"\n", " ");
htmlResult = Regex.Replace(htmlResult, @"\s{2,}", " ");
htmlResult = Regex.Replace(htmlResult, @"\\", @"\\");
htmlResult = Regex.Replace(htmlResult, @"[']", @"\'");
这也消除了所有回车和不必要的空格。我目前使用的是(稍微修改过的版本)。
对我来说很好!为什么要保留所有的空白?
string htmlResult = "/*string*/";
htmlResult = Regex.Replace(htmlResult, @"\r\n", " ");
htmlResult = Regex.Replace(htmlResult, @"\n", " ");
htmlResult = Regex.Replace(htmlResult, @"\s{2,}", " ");
htmlResult = Regex.Replace(htmlResult, @"\\", @"\\");
htmlResult = Regex.Replace(htmlResult, @"[']", @"\'");