public static String trim(String list,String delimiter,int[] removeInfo,boolean multiCharacterDelimiter){
  if (list.length() == 0)   return "";
  if (multiCharacterDelimiter && delimiter.length() > 1) {
    int from=0;
    while (list.length() >= from + delimiter.length()) {
      if (list.indexOf(delimiter,from) == from) {
        from+=delimiter.length();
        removeInfo[0]++;
        continue;
      }
      break;
    }
    if (from > 0)     list=list.substring(from);
    while (list.length() >= delimiter.length()) {
      if (list.lastIndexOf(delimiter) == list.length() - delimiter.length()) {
        removeInfo[1]++;
        list=list.substring(0,list.length() - delimiter.length());
        continue;
      }
      break;
    }
    return list;
  }
  if (list.length() == 0)   return "";
  int from=0;
  int to=list.length();
  char[] del=delimiter.toCharArray();
  char c;
  outer:   while (list.length() > from) {
    c=list.charAt(from);
    for (int i=0; i < del.length; i++) {
      if (c == del[i]) {
        from++;
        removeInfo[0]++;
        continue outer;
      }
    }
    break;
  }
  outer:   while (to > from) {
    c=list.charAt(to - 1);
    for (int i=0; i < del.length; i++) {
      if (c == del[i]) {
        to--;
        removeInfo[1]++;
        continue outer;
      }
    }
    break;
  }
  int newLen=to - from;
  if (newLen < list.length()) {
    return list.substring(from,to);
  }
  return list;
}

public static String trim ( String list , String delimiter , int [ ] removeInfo , boolean multiCharacterDelimiter ) { if ( list . length ( ) == 0 ) return "" ; if ( multiCharacterDelimiter && delimiter . length ( ) > 1 ) { int from = 0 ; while ( list . length ( ) >= from + delimiter . length ( ) ) { if ( list . indexOf ( delimiter , from ) == from ) { from += delimiter . length ( ) ; removeInfo [ 0 ] ++ ; continue ; } break ; } if ( from > 0 ) list = list . substring ( from ) ; while ( list . length ( ) >= delimiter . length ( ) ) { if ( list . lastIndexOf ( delimiter ) == list . length ( ) - delimiter . length ( ) ) { removeInfo [ 1 ] ++ ; list = list . substring ( 0 , list . length ( ) - delimiter . length ( ) ) ; continue ; } break ; } return list ; } if ( list . length ( ) == 0 ) return "" ; int from = 0 ; int to = list . length ( ) ; char [ ] del = delimiter . toCharArray ( ) ; char c ; outer : while ( list . length ( ) > from ) { c = list . charAt ( from ) ; for ( int i = 0 ; i < del . length ; i ++ ) { if ( c == del [ i ] ) { from ++ ; removeInfo [ 0 ] ++ ; continue outer ; } } break ; } outer : while ( to > from ) { c = list . charAt ( to - 1 ) ; for ( int i = 0 ; i < del . length ; i ++ ) { if ( c == del [ i ] ) { to -- ; removeInfo [ 1 ] ++ ; continue outer ; } } break ; } int newLen = to - from ; if ( newLen < list . length ( ) ) { return list . substring ( from , to ) ; } return list ; }
trims a string list , remove all empty delimiter at start and the end
