public static String[] splitOnCharWithQuoting(String s,char splitChar,char quoteChar,char escapeChar){
  List<String> result=new ArrayList<String>();
  int i=0;
  int length=s.length();
  StringBuffer b=new StringBuffer();
  while (i < length) {
    char curr=s.charAt(i);
    if (curr == splitChar) {
      if (b.length() > 0) {
        result.add(b.toString());
        b=new StringBuffer();
      }
      i++;
    }
 else     if (curr == quoteChar) {
      i++;
      while (i < length) {
        curr=s.charAt(i);
        if (curr == escapeChar) {
          b.append(s.charAt(i + 1));
          i+=2;
        }
 else         if (curr == quoteChar) {
          i++;
          break;
        }
 else {
          b.append(s.charAt(i));
          i++;
        }
      }
    }
 else {
      b.append(curr);
      i++;
    }
  }
  if (b.length() > 0) {
    result.add(b.toString());
  }
  return result.toArray(new String[0]);
}

public static String [ ] splitOnCharWithQuoting ( String s , char splitChar , char quoteChar , char escapeChar ) { List < String > result = new ArrayList < String > ( ) ; int i = 0 ; int length = s . length ( ) ; StringBuffer b = new StringBuffer ( ) ; while ( i < length ) { char curr = s . charAt ( i ) ; if ( curr == splitChar ) { if ( b . length ( ) > 0 ) { result . add ( b . toString ( ) ) ; b = new StringBuffer ( ) ; } i ++ ; } else if ( curr == quoteChar ) { i ++ ; while ( i < length ) { curr = s . charAt ( i ) ; if ( curr == escapeChar ) { b . append ( s . charAt ( i + 1 ) ) ; i += 2 ; } else if ( curr == quoteChar ) { i ++ ; break ; } else { b . append ( s . charAt ( i ) ) ; i ++ ; } } } else { b . append ( curr ) ; i ++ ; } } if ( b . length ( ) > 0 ) { result . add ( b . toString ( ) ) ; } return result . toArray ( new String [ 0 ] ) ; }
this function splits the string s into multiple strings using the splitchar . however , it provides an quoting facility : it is possible to quote strings with the quotechar . if the quotechar occurs within the quotedexpression , it must be prefaced by the escapechar
