trim Space only from string - Android java.lang

Android examples for java.lang:String Strip

Description

trim Space only from string

Demo Code


public class Main{

    /**/*from   w  w w . j  a v a2 s. com*/
     * Method trim space
     *
     * @param The string to be format.
     *
     */
    public static String trimSpace(String oldString) {
        if (null == oldString)
            return null;
        if (0 == oldString.length())
            return "";

        StringBuffer sbuf = new StringBuffer();
        int oldLen = oldString.length();
        for (int i = 0; i < oldLen; i++) {
            if (' ' != oldString.charAt(i))
                sbuf.append(oldString.charAt(i));
        }
        String returnString = sbuf.toString();
        sbuf = null;
        return returnString;
    }

}

Related Tutorials