public static String validName ( String name ) { if ( name == null || name . trim ( ) . isEmpty ( ) ) { return "unnamed" ; } StringBuilder result = new StringBuilder ( ) ; for ( char c : name . toCharArray ( ) ) { if ( c == ' ' || c == ' ' || Character . isLetterOrDigit ( c ) ) { result . append ( c ) ; } } return result . toString ( ) ; }
Returns a valid name for variables