public static String escapeWithBackslash ( String value , String metachars ) { StringBuffer sb = new StringBuffer ( ) ; int i , n = value . length ( ) ; char ch ; for ( i = 0 ; i < n ; i ++ ) { ch = value . charAt ( i ) ; if ( ch == ' ' || metachars . indexOf ( ch ) >= 0 ) { sb . append ( ' ' ) ; } sb . append ( ch ) ; } return sb . toString ( ) ; }
Escape meta characters with backslash .