java-trim-不仅仅过滤掉空格

结论,会过滤掉小于等于空格的字符,主要是用于打印的不可见字符,如回车、制表符、换行符等等

java-trim-不仅仅过滤掉空格_第1张图片 

/**
     * Returns a string whose value is this string, with any leading and trailing
     * whitespace removed.
     * 

* If this {@code String} object represents an empty character * sequence, or the first and last characters of character sequence * represented by this {@code String} object both have codes * greater than {@code '\u005Cu0020'} (the space character), then a * reference to this {@code String} object is returned. *

* Otherwise, if there is no character with a code greater than * {@code '\u005Cu0020'} in the string, then a * {@code String} object representing an empty string is * returned. *

* Otherwise, let k be the index of the first character in the * string whose code is greater than {@code '\u005Cu0020'}, and let * m be the index of the last character in the string whose code * is greater than {@code '\u005Cu0020'}. A {@code String} * object is returned, representing the substring of this string that * begins with the character at index k and ends with the * character at index m-that is, the result of * {@code this.substring(k, m + 1)}. *

* This method may be used to trim whitespace (as defined above) from * the beginning and end of a string. * * @return A string whose value is this string, with any leading and trailing white * space removed, or this string if it has no leading or * trailing white space. */ public String trim() { int len = value.length; int st = 0; char[] val = value; /* avoid getfield opcode */ while ((st < len) && (val[st] <= ' ')) { st++; } while ((st < len) && (val[len - 1] <= ' ')) { len--; } return ((st > 0) || (len < value.length)) ? substring(st, len) : this; }

你可能感兴趣的:(java,python,前端)