Doniyor Niyozov Doniyor Niyozov - 12 days ago 5
C# Question

Cannot remove a new line from text

I have this text.There is a new line before

</ul>
tag. So I could't remove that line with this code.

str = str.Replace(Environment.NewLine,"");


But this code is working for just usual string.

<h2><a class="ms-wikilink" href="/Pages/Test.aspx">Test1</a></h2>
<ul style="list-style-type&#58;circle;">
<li>
<a class="ms - wikilink" href="/Test.aspx">Test1</a>
</li><li>
<a class="ms - wikilink" href="/Test.aspx">Test Feature</a>
</li>
<li><h2 class="ms-wikilink">Test</h2>
<ul style="list-style-type&#58;circle;">
<li>
<a class="ms - wikilink" href="/Test.aspx">Test Feature</a>
</li><li>
<a class="ms - wikilink" href="/Test.aspx">Test Feature</a>
</li>

</ul>
</li>
</ul>


Can someone help me on that?

Thanks!

Answer

You can remove it with Regex easily

Regex.Replace(stringValue, @"\t|\n|\r", "");

I hope it helps!