trim String Leading Whitespace - Android java.lang

Android examples for java.lang:String Strip

Description

trim String Leading Whitespace

Demo Code

import android.text.Html;
import android.text.Spanned;
import java.util.ArrayList;
import java.util.List;

public class Main{


    public static String trimLeadingWhitespace(String str) {
        if (!hasLength(str)) {
            return str;
        }/*www .  j  av  a2s .  co  m*/
        StringBuffer buf = new StringBuffer(str);
        while (buf.length() > 0 && Character.isWhitespace(buf.charAt(0))) {
            buf.deleteCharAt(0);
        }
        return buf.toString();
    }

}

Related Tutorials