checking virtual key range: 'a-z' and 'A-Z'

  • Thread starter Thread starter farseer
  • Start date Start date
F

farseer

if i wanted to check if a virtual key is in the range of 'a-z' or 'A-Z'
is there an easy way to do this in C#?
 
farseer said:
if i wanted to check if a virtual key is in the range of 'a-z' or 'A-Z'
is there an easy way to do this in C#?


What do you mean by virtual key?

If you want to ensure a single character is in that range it'd be easiest
just to do a comparison on all 4 ends to determine the character is in the
range(Char.IsLetter includes more than just a-z). If you are working with
strings regex probably the way to go.
 
a thanks...haven't tried it yet, but i am guessing from what you say,
this should return true:

int vkKey = 65;
bool vkIsLetter = Char.IsLetter( (char) vkKey )
 
farseer said:
a thanks...haven't tried it yet, but i am guessing from what you say,
this should return true:

int vkKey = 65;
bool vkIsLetter = Char.IsLetter( (char) vkKey )

Well, Char.IsLetter will return true in far more cases than a-z and A-Z,
although it will return true in those cases, it is still not ideal.
Something more like(untested)

bool IsInAToZRange(char c)
{
if (c >= 0x41 && c <= 0x5A)
return true; //between A-Z
if (c >=0x61 && c<=0x7A)
return true; //between a-z
return false;
}
 
Daniel O'Connell posted a simple method to do the job. Since he
compared with hexvalues I wanted to point out that it is possible to
directly compare with character literals. Here is my solution:

bool IsEnglishLetter(char c)
{
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
}
 
thanks all, i appreciate your assistance. the last two was what i was
looking for. thanks Daniel and Marcus
 
Back
Top