android/guava/src/com/google/common/base/CharMatcher.java
public String trimFrom(CharSequence sequence) {
    int len = sequence.length();
    int first;
    int last;

    for (first = 0; first < len; first++) {
      if (!matches(sequence.charAt(first))) {
        break;
      }
    }
    for (last = len - 1; last > first; last--) {
      if (!matches(sequence.charAt(last))) {
        break;
      }
    }

    return sequence.subSequence(first, last + 1).toString();
  }
public String trimFrom(CharSequence sequence) {
    int len = sequence.length();
    int first;
    int last;

    for (first = 0; first < len; first++) {
      if (!matches(sequence.charAt(first))) {
        break;
      }
    }
    for (last = len - 1; last > first; last--) {
      if (!matches(sequence.charAt(last))) {
        break;
      }
    }

    return sequence.subSequence(first, last + 1).toString();
  }
public String trimFrom ( CharSequence sequence ) { int len = sequence . length ( ) ; int first ; int last ; for ( first = 0 ; first < len ; first ++ ) { if ( ! matches ( sequence . charAt ( first ) ) ) { break ; } } for ( last = len - 1 ; last > first ; last -- ) { if ( ! matches ( sequence . charAt ( last ) ) ) { break ; } } return sequence . subSequence ( first , last + 1 ) . toString ( ) ; }
Returns a substring of the input character sequence that omits all matching BMP characters from
the beginning and from the end of the string. For example:

<pre>{@code
CharMatcher.anyOf("ab").trimFrom("abacatbab")
}</pre>

... returns {@code "cat"}.

<p>Note that:

<pre>{@code
CharMatcher.inRange('\0', ' ').trimFrom(str)
}</pre>

... is equivalent to {@link String#trim()}.
Returns a substring of the input character sequence that omits all matching BMP characters from the beginning and from the end of the string . For example :