public static String escape(String input){
  boolean insidequote=false;
  String output="";
  for (int i=0; i < input.length(); i++) {
    char current=input.charAt(i);
    if (current == '\'') {
      insidequote=!insidequote;
      output+=current;
    }
 else     if (insidequote) {
      if (current == ' ') {
        output+="\\s";
      }
 else       if (current == '\t') {
        output+="\\t";
      }
 else       if (current == ',') {
        output+="\\c";
      }
 else       if (current == '\\') {
        output+="\\b";
      }
 else       if (current == ';') {
        output+="\\p";
      }
 else       if (current == ':') {
        output+="\\d";
      }
 else {
        output+=current;
      }
    }
 else {
      if (current == ',') {
        output+=" , ";
      }
 else {
        output+=current;
      }
    }
  }
  return output;
}

public static String escape ( String input ) { boolean insidequote = false ; String output = "" ; for ( int i = 0 ; i < input . length ( ) ; i ++ ) { char current = input . charAt ( i ) ; if ( current == '\'' ) { insidequote = ! insidequote ; output += current ; } else if ( insidequote ) { if ( current == ' ' ) { output += "\\s" ; } else if ( current == '\t' ) { output += "\\t" ; } else if ( current == ',' ) { output += "\\c" ; } else if ( current == '\\' ) { output += "\\b" ; } else if ( current == ';' ) { output += "\\p" ; } else if ( current == ':' ) { output += "\\d" ; } else { output += current ; } } else { if ( current == ',' ) { output += " , " ; } else { output += current ; } } } return output ; }
escapes spaces , tabs and commas inside any apostrophe - enclosed subsections of the input string . e . g . in " a ' b c ' " , the space between b and c would be escaped . also uppercases all characters that are not inside a quoted string .
