Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot remove a new line from text

Tags:

string

c#

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.

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

</ul>
like image 696
Doniyor Niyozov Avatar asked Nov 29 '16 04:11

Doniyor Niyozov


Video Answer


2 Answers

You can remove it with Regex easily

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

I hope it helps!

like image 52
Ahror Kayumov Avatar answered Oct 16 '22 02:10

Ahror Kayumov


This might do the trick for you

var regex = new Regex(@"(?<=>)\s+?(?=<)", RegexOptions.Multiline);
var outstr = regex.Replace(YourHTMLString,"");
like image 33
Mohit S Avatar answered Oct 16 '22 01:10

Mohit S