Below is the suggested solution in Java to strip off whitespace characters without using regular expressions. The code itself is quite straight forward. "NicholasKey" will be returned as the result of this method with the given input "Nicholas Key".
Update: The code is also available in Python in this entry
public static String stripWhiteSpace(String text){
StringBuffer cleanText = new StringBuffer();
int len = text.length();
for (int i=0; i<len; i++) {
if (text.charAt(i) != ' ') {
cleanText.append(text.charAt(i));
}
}
return cleanText.toString();
}
0 comments:
Post a Comment