public static String fileNameClean ( String s ) { char [ ] chars = s . toCharArray ( ) ; StringBuilder sb = new StringBuilder ( ) ; for ( char c : chars ) { if ( ( c >= ' ' && c <= ' ' ) || ( c >= ' ' && c <= ' ' ) || ( c >= ' ' && c <= ' ' ) || ( c == ' ' ) ) { sb . append ( c ) ; } else { if ( c == ' ' || c == ' ' ) { sb . append ( ' ' ) ; } else { sb . append ( ' ' ) . append ( ( int ) c ) . append ( ' ' ) ; } } } return sb . toString ( ) ; }
Returns a clean version of the given filename in which spaces have been converted to dashes and all non - alphanumeric chars are underscores .