public static String quotedString(String str){
  if (str == null) {
    return null;
  }
  StringBuilder sb=new StringBuilder();
  sb.append("\"");
  for (int i=0; i < str.length(); i++) {
    char ch=str.charAt(i);
    if ((ch == '\'') || (ch == '"')) {
      if ((i > 0) && (str.charAt(i - 1) != '\\')) {
        sb.append('\\');
      }
 else       if (i == 0) {
        sb.append('\\');
      }
    }
    sb.append(ch);
  }
  sb.append("\"");
  return sb.toString();
}

public static String quotedString ( String str ) { if ( str == null ) { return null ; } StringBuilder sb = new StringBuilder ( ) ; sb . append ( "\"" ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { char ch = str . charAt ( i ) ; if ( ( ch == '\'' ) || ( ch == '"' ) ) { if ( ( i > 0 ) && ( str . charAt ( i - 1 ) != '\\' ) ) { sb . append ( '\\' ) ; } else if ( i == 0 ) { sb . append ( '\\' ) ; } } sb . append ( ch ) ; } sb . append ( "\"" ) ; return sb . toString ( ) ; }
return a double - quoted string with inner single and double quotes escaped .
