Subscribe For Free Updates!

We'll not spam mate! We promise.

Feb 15, 2013

Remove Empty Lines from String or XML

Views:

To day I will show you How to Remove Empty Lines from string variable or  string Variable containing XML Data .

This Code will Work on Both C# and Java Language.

In Code I use Reg-ex Expression  To Detect or Find empty lines from String and Replace any other Character , join with Previous line or Else ..


Lets Start ;

String text = "line 1\n\nline 3\n\n\nline 5";
String adjusted = text.replaceAll("(?m)^[ \t]*\r?\n", "");

the String Variable adjusted Contain String Data With on empty Lines.
I Also Tested It with JavaScript and IT Works Fine.

Plese Feel Free to Socializer This Post
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments:

Post a Comment

Become a Fan

visual studio learn