I want to split the /n from my string in Java. For example, I have one String field which has 2 lines space ( /n). I have to find out lines ( wherever mopre than one lines is coming) and should replace with one line spaces.
"This is Test Message
thanks
Zubair
"
From the above example, there are more spaces between “This is Test Message” and “thanks”. So i want to reduce as only one line instead of 2 lines.How to do that?
I don’t know how to use regex, but you can use a StringTokenizer:
This splits the string on line breaks, then adds each line to a new string (the tokenizer treats multiples of its delimiter as one, so you’ll be left with just one line break between lines).