What I'm trying to do is format input from a text area so that it is all uppercase letters and numbers, eliminating all punctuatoin and whitespace. I want to use a method format() to loop through all the characters in the text and use a switch statement to determine whether the character is A-Z or 0-9. If it is, I want to append the character to the end of a new String variable. Something like this, with "text" and "newText" as global String variables:
public static void format() {
char letter = 0;
text = text.toUpperCase();
for( i = 0; i < text.length(); i++ ) {
letter = text.charAt( i ) ;
switch( letter ) {
case A:
newText = newText + letter;
break;
case B:
newText = newText + letter;
break;
//... and so on from A-Z and 0-9
}
}
The problem is that it won't allow me to use the data type "char" for a switch statement (it thinks A, B, C, and so on are variables), and I'm guessing you probably can't append a "char" to a string either. Is there a function I can use in place of "charAt()" to get the characters from "text" and give them the data type "String" instead of "char"? Also, if so, will "Sting" work in a switch statement? For instance:
// I want "letter" to be a string variable in this case
switch( letter ) {
case A:
newText = newText + letter;
break;
case B:
... and so on
And one last question, is there a better way to check the character than using the long switch statement?
Thanks in advance!
EvilObsidian :twisted: