replace \n in string

Posted on 2006-05-24
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";
            s = s.replace("\n", "");

why doesnt it work for \n ?
Question by:hoomanv
    LVL 92

    Expert Comment

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

    Author Comment

    illegal escape character
         s = s.replaceAll("\s", "");
    LVL 92

    Accepted Solution

    sorry abouit that, u need to escape it

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

    Author Comment

    very well done :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now