Pages

Thursday, June 9, 2011

How To Remove Extra Spaces From String


public static String LRTrim(String str) {

        str = str.replaceAll("  ", " ");         // replace all double spaces with single Space
        return str.trim();   // remove all LEFT side & Right Side Extra white spaces from the string
    }

2 comments:

  1. Bro, in the above code you can make a change by not using while. Because that will remove the spaces between the words also. Right? So only trim is ok.

    ReplyDelete
  2. thanks buddy. i know we have to remove while statement.
    str = str.replaceAll(" "," ");
    use to remove duplicate spaces from the string.


    this is just a example.
    go through other posts

    ReplyDelete

Thank you for your valuable comments on http://www.smartphonebysachin.blogspot.com.