Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

converting a multi-line text to one-line

807598Aug 4 2006 — edited Aug 4 2006
Hi

I have a problem with a multi-line text, to be converted to one line, which I take from a JEditorPane.
I tried several things but it is still multi line
// the text is taken from JEditorPane
String str = jeditorPane.getText();
			
// replace "\n" with " "
str.replaceAll("\\n", " ");
or
// the text is taken from JEditorPane
String str = jeditorPane.getText();

Scanner s = new Scanner(str);

String line;
String completeText="";
while( ( line = str.nextLine() ) != null  ){
      completeText += line + " ";
}
In the fist code, it replaces all the "\n"'s with a space but it is still multi-line
in the second one, it doesn't change anything

So, what is wrong with these codes?

p.s. In the second code there (may) be a little mistake causing compile time error, please ignore that, my problem is with the logic of the code

thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 1 2006
Added on Aug 4 2006
3 comments
430 views