switch keyword...

  • Thread starter Thread starter Colin Basterfield
  • Start date Start date
C

Colin Basterfield

Hi,

Coming back to C# after a foray back into Delphi 7, and I wanted to use the
switch keyword to do the following:

switch (pwdChar)
{
case "a".."z":
case "A".."Z":
case "0".."9":
// do something
// break
default : break;
}

But it doesn't recognize that a..z means any letter between a and z, is this
possible?

TIA
Colin
 
Colin,
I don't think switch\case will do that for you. You might take a look at the RegEx class.

You might look at these functions too.

char.IsLetter();
char.IsNumber();
char.IsUpper();
char.IsLower();

Jason Newell, MCAD
Software Engineer
 
Colin,

a) There are no subranges in C#. You'll have to list explicitly all cases or
use nested if statements instead of the switch.
b) Careful! You've writtten "a", "z", etc. (string literals), and you
probably meant 'a', 'z', etc.(char literals). They're not the same thing.

Regards,

Octavio
 
Hi,

I also see Char.IsLetterOrDigit is a valid function, that looks useful,
thanks for the pointer, no not ^! :-)

Cheers
Colin
 
Hi,

That makes sense, see my other reply, but thanks for differentiating the "
against the ', I hadn't realised that, it is iall these little things that
make these languages so much fun ay? :-)

Cheers
Colin
 
Back
Top