Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将html标记转换为JavaScript兼容字符串的C#方法_C#_Javascript_Jquery_Html - Fatal编程技术网

将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, @"[']", @"\'");