473,385 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

switch keyword...

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
Nov 17 '05 #1
4 4610
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 Basterfield wrote:
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

Nov 17 '05 #2
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

"Colin Basterfield" <co**************@hotmail.com> escribió en el mensaje
news:%2****************@TK2MSFTNGP15.phx.gbl...
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

Nov 17 '05 #3
Hi,

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

Cheers
Colin
"Jason Newell" <no****@nospam.com> wrote in message
news:OZ**************@TK2MSFTNGP10.phx.gbl...
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 Basterfield wrote:
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

Nov 17 '05 #4
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

"Octavio Hernandez" <do****@danysoft.com> wrote in message
news:eX**************@TK2MSFTNGP09.phx.gbl...
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

"Colin Basterfield" <co**************@hotmail.com> escribió en el mensaje
news:%2****************@TK2MSFTNGP15.phx.gbl...
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


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Christian Seberino | last post by:
I know IPython is another interpreter for Python and was wondering what people liked about it and if I should switch to it. If it is so good then why is it not part of the standard Python...
21
by: Andy | last post by:
Can someone tell me if the following Switch...Case construct is valid? I'm wanting to check for multiple values in the Case statement without explicitly listing each values. So for example, will...
5
by: Nadav | last post by:
Hi, I am using FileStream's Async API: BeginRead/EndRead, upon completion callback execution I use the read data and call EndRead, Taking that in mind, I Wonder... does calling EndRead will cause...
13
by: Adam Blair | last post by:
Is it possible to bind a switch statement to an Enum such that a compile-time error is raised if not all values within the Enum are handled in the switch statement? I realise you can use default:...
13
by: PeterZ | last post by:
Hi, Back to basics! My understanding is that the only way to exit a For-Next loop prematurely is with the 'break' keyword. How are you supposed to do that if you're inside a Switch...
24
by: Mark | last post by:
Hi - how can I get a switch statement to look for a range of values? I have: function payCalc(field, field2) switch(field.value) { case 0-50: field2.value="lower band"; case 51-99:...
14
by: Evan Camilleri | last post by:
I am going from VB.NET to c#. How can I do the following? switch x { case < 10: do something; break; case < 50: do something; break;
2
NewYorker
by: NewYorker | last post by:
Write a switch statement that tests the value of the char variable response and performs the following actions: if response is y , the message Your request is being processed is printed if ...
6
by: asadikhan | last post by:
Hello, I have a bit of a design issue around this application I am developing, and I just want to run it through some of the brains out here. So I have a table called ErrorCheck which...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.