static protected String[] splitLineCSV(String line){
  char[] c=line.toCharArray();
  int rough=1;
  boolean quote=false;
  for (int i=0; i < c.length; i++) {
    if (!quote && (c[i] == ',')) {
      rough++;
    }
 else     if (c[i] == '\"') {
      quote=!quote;
    }
  }
  String[] pieces=new String[rough];
  int pieceCount=0;
  int offset=0;
  while (offset < c.length) {
    int start=offset;
    int stop=nextComma(c,offset);
    offset=stop + 1;
    if (c[start] == '\"' && c[stop - 1] == '\"') {
      start++;
      stop--;
    }
    int i=start;
    int ii=start;
    while (i < stop) {
      if (c[i] == '\"') {
        i++;
      }
      if (i != ii) {
        c[ii]=c[i];
      }
      i++;
      ii++;
    }
    String s=new String(c,start,ii - start);
    pieces[pieceCount++]=s;
  }
  for (int i=pieceCount; i < pieces.length; i++) {
    pieces[i]="";
  }
  return pieces;
}

static protected String [ ] splitLineCSV ( String line ) { char [ ] c = line . toCharArray ( ) ; int rough = 1 ; boolean quote = false ; for ( int i = 0 ; i < c . length ; i ++ ) { if ( ! quote && ( c [ i ] == ',' ) ) { rough ++ ; } else if ( c [ i ] == '\"' ) { quote = ! quote ; } } String [ ] pieces = new String [ rough ] ; int pieceCount = 0 ; int offset = 0 ; while ( offset < c . length ) { int start = offset ; int stop = nextComma ( c , offset ) ; offset = stop + 1 ; if ( c [ start ] == '\"' && c [ stop - 1 ] == '\"' ) { start ++ ; stop -- ; } int i = start ; int ii = start ; while ( i < stop ) { if ( c [ i ] == '\"' ) { i ++ ; } if ( i != ii ) { c [ ii ] = c [ i ] ; } i ++ ; ii ++ ; } String s = new String ( c , start , ii - start ) ; pieces [ pieceCount ++ ] = s ; } for ( int i = pieceCount ; i < pieces . length ; i ++ ) { pieces [ i ] = "" ; } return pieces ; }
parse a line of text as comma - separated values , returning each value as one entry in an array of string objects . remove quotes from entries that begin and end with them , and convert ' escaped ' quotes to actual quotes .
