public static String quote ( String str ) { int len = str . length ( ) ; StringBuffer buf = new StringBuffer ( len + 2 ) ; buf . append ( "\"" ) ; char c ; for ( int i = 0 ; i < len ; i ++ ) { c = str . charAt ( i ) ; if ( c == ' ' || c == ' ' ) { buf . append ( "\\" ) ; } buf . append ( c ) ; } buf . append ( "\"" ) ; return buf . toString ( ) ; }
Quotifies a specified string . The entire string is encompassed by double quotes and each is replaced with \ \ is replaced with \\ .