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()