Hey there! any question in your mind? Ask It Now!.

Popular Categories





How to remove line breaks from a string in java?

+3 votes
768 views
asked in Programming by monika (2,040 points)
hello guys I want to know how can I remove all line breaks from a string which is coming from a web page dynamically.Thanks For Help.

1 Answer

+1 vote
answered by Eathen (1,930 points)
Hey monika , If you are getting line breaks from a String so you need to replace \n then you have to replace \r, let me see you how with a example
Here we have a text file suppose sample.txt now we have to remove all line breaks from this file. See the Code
 
 String strTextFile = readFileAsString("sample.txt");
strTextFile = strTextFile.replace("\n", "").replace("\r", "");
 
I hope you got my point like the same way you can remove line breaks from your dynamic strings.
 
 
 
 

Related Questions

–1 vote
0 answers 145 views
+2 votes
2 answers 799 views
+6 votes
2 answers 2,765 views
+2 votes
1 answer 171 views
+1 vote
1 answer 875 views
0 votes
1 answer 190 views
+4 votes
5 answers 756 views
+2 votes
1 answer 705 views
+3 votes
1 answer 410 views
+1 vote
1 answer 113 views

Not a Member yet?

Ask to Folks Login

My Account
444 Folks are online
2 members and 442 guest online
Your feedback is highly appreciated