Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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
C# 尝试替换字符串中的某些文本_C#_C# 4.0 - Fatal编程技术网

C# 尝试替换字符串中的某些文本

C# 尝试替换字符串中的某些文本,c#,c#-4.0,C#,C# 4.0,我有一些文字: <p style="font-family: arial narrow;font-size: 11;font-style: normal;"> {<span data-scaytid="11" data-scayt_word="APP_PRVRIYTable" style= "background-color: rgb(255, 255, 255);">APP_IRVRIYTable}</span></p> {APP_IRVRI

我有一些文字:

<p style="font-family: arial narrow;font-size: 11;font-style: normal;">
{<span data-scaytid="11" data-scayt_word="APP_PRVRIYTable" style=
"background-color: rgb(255, 255, 255);">APP_IRVRIYTable}</span></p>

{APP_IRVRIYTable}

我需要将其转换为:

<p style="font-family: arial narrow;font-size: 11;font-style: normal;">
<span></span></p>

我开始考虑“replace”和“substring”函数,但想知道是否有一种雄辩的方法来实现这一点


谢谢。

我想下面的一个方法就行了

在您的字符串中,我认为Remove将是最好的选择,否则编写您自己的函数来完成这项工作

str = str.Remove(str.Length - YourLastLettersCount);


循环遍历字符串并使用StringBuilder创建新字符串可能会更快

最好将此字符串解析为XML或HTML并使用常规DOM方法。使用HTML解析器。例如,HtmlAgilityPack。我正在使用TidyManaged,它是围绕htmlidy的包装器,所以可能我遗漏了一些东西。在它目前的设置中,它并没有去掉这个,因此我发现了这个错误。
 Substring()
 Replace()