Java String Trim Left leftTrim(StringBuilder pStringBuilder)

Here you can find the source of leftTrim(StringBuilder pStringBuilder)

Description

Similar to the Perl chomp command.

License

Open Source License

Parameter

Parameter Description
pStringBuilder The StringBuffer object to remove leading and trailing whitespace characters from.

Return

StringBuffer the chomped string.

Declaration

public static StringBuilder leftTrim(StringBuilder pStringBuilder) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from ww w.  ja  v  a  2s. co  m
     * Similar to the Perl chomp command. Removes all leading
     * whitespace.
     *
     * @param pStringBuilder The StringBuffer object to remove leading and trailing whitespace
     * characters from.
     * @return StringBuffer the chomped string.
     */
    public static StringBuilder leftTrim(StringBuilder pStringBuilder) {
        while (true) {
            if (pStringBuilder.length() != 0 && Character.isWhitespace(pStringBuilder.charAt(0))) {
                pStringBuilder.deleteCharAt(0);
            } else {
                break;
            }
        }

        return pStringBuilder;
    }

    /**
     * Similar to the Perl chomp command. Removes all leading
     * whitespace.
     *
     * @param pString The String object to remove leading and trailing whitespace
     * characters from.
     * @return String the chomped string.
     */
    public static String leftTrim(String pString) {
        return leftTrim(new StringBuilder(pString)).toString();
    }
}

Related

  1. leftTrim(String str)
  2. lefttrim(String str)
  3. leftTrim(String str)
  4. leftTrim(String string)
  5. leftTrim(String value)
  6. leftTrimSlashes(String s)
  7. ltrim(byte[] a)
  8. ltrim(CharSequence str)
  9. ltrim(final String str)