public static String escapeDelimitedColumn ( String str , char delimiter ) { if ( str == null || ( containsNone ( str , SEARCH_CHARS ) && str . indexOf ( delimiter ) < 0 ) ) { return str ; } else { StringBuilder writer = new StringBuilder ( ) ; writer . append ( QUOTE ) ; for ( int j = 0 , n = str . length ( ) ; j < n ; j ++ ) { char c = str . charAt ( j ) ; if ( c == QUOTE ) { writer . append ( QUOTE ) ; } writer . append ( c ) ; } writer . append ( QUOTE ) ; return writer . toString ( ) ; } }
Escapes a column in a delimited file .