ignoring the case
How does one integrate ignoring the case of an inputted character into a switch statement or while statement?
I know this
while("Y".equalsIgnoreCase(answer))
but I'd like to know how to do this for characters in a switch statement and while statement.
Thanks
[348 byte] By [
datawerda] at [2007-11-26 20:02:25]

I would do it in a while statement.
char a = 'a', b = 'b';
while( a.toLowerCase().equals(b.toLowerCase()) )
//and
while ( a.toUpperCase().equals(b.toUpperCase() )
For a switch (I would rather us a while loop)
char a = 'a', b = 'b';
char a1 = a.toLowerCase(), a2 = a.toUpperCase(), b1 = b.toLowerCase(), b2 = b2.toUpperCase
switch(a) {
case a1: //code
break;
case a2: //code
break;
case b1: //code
break;
case b2:: //code
break;
}
The logic makes a lot of sense, but I thought you couldn't use the 'equals' operator on char types?!? Maybe it would be simpler to use String instead of char, but I want to use as little memory as is needed.
Sorry sorry. My syntax is incorrect.
Should be
Character b1= Character.toUpperCase(b);
or
Character b2 = Character.toLowerCase(b);
*Edit
Also noting that you can write
char b = 'b';
char b1 = Character.toUpperCase(b);
char b2 = Character.toLowerCase(b);
Message was edited by:
lethalwire
Message was edited by:
lethalwire
Message was edited by:
lethalwire