Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

replace \n in string

Posted on 2006-05-24
4
Medium Priority
?
351 Views
Last Modified: 2010-03-31
I want to remove \r\n + \n + whitespace including tab and space in a string

            String s = "\n \thello\t \r\n";
            System.out.println(s);
            s = s.replace("\n", "");
            System.out.println(s);

why doesnt it work for \n ?
0
Comment
Question by:hoomanv
  • 2
  • 2
4 Comments
 
LVL 92

Expert Comment

by:objects
ID: 16758022
s = s.replaceAll("\s", "");
0
 
LVL 14

Author Comment

by:hoomanv
ID: 16758028
illegal escape character
     s = s.replaceAll("\s", "");
                              ^
0
 
LVL 92

Accepted Solution

by:
objects earned 396 total points
ID: 16758043
sorry abouit that, u need to escape it

s = s.replaceAll("\\s", "");
0
 
LVL 14

Author Comment

by:hoomanv
ID: 16758049
very well done :)
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question