public static String remove ( final String string , final char ch ) { int stringLen = string . length ( ) ; char [ ] result = new char [ stringLen ] ; int offset = 0 ; for ( int i = 0 ; i < stringLen ; i ++ ) { char c = string . charAt ( i ) ; if ( c == ch ) { continue ; } result [ offset ] = c ; offset ++ ; } if ( offset == stringLen ) { return string ; // no changes } return new String ( result , 0 , offset ) ; }
Removes a single character from string .