我有一个字符串如下:
<p>Message Pilcrow</p><p>Testing....</p><br/><p>testing in progress...</p>
^^^ ^^^^
我需要以下字符串作为结果:
Message Pilcrow<p>Testing....</p><br/><p>testing in progress...</p>
答案 0 :(得分:1)
这很简单:
string yourstring = "<p>Message Pilcrow</p><p>Testing....</p><br/><p>testing in progress...</p>";
Regex rgx = new Regex("<p>|</p>");
string res = rgx.Replace(yourstring, "", 2);
Console.WriteLine(res);
此处,&#39; 2&#39; 表示更换发生的次数。
这将按预期提供以下输出:
Message Pilcrow<p>Testing....</p><br/><p>testing in progress...</p>
答案 1 :(得分:-1)
试试这个:
string msg = "<p>Message Pilcrow</p><p>Testing....</p><br/><p>testing in progress...</p>";
String res1 = msg.Replace("</p>", ";");
string res2 = res1.Replace("<p>", "");
string res3 = res2.Replace("<br/>", "");
String[] arr = new string[3];
arr = res3.Split(';');
string res = arr[0].ToString() + "<p>" + arr[1].ToString() + "</p><br/><p>" + arr[2].ToString() + "</p>";
结果返回:
Message Pilcrow<p>Testing....</p><br/><p>testing in progress...</p>