how do I make sure that the user has entered a character contained in the alphabet
Printable View
how do I make sure that the user has entered a character contained in the alphabet
Check the character's value against 'A'..'Z' and 'a'..'z'. If it is between one of them, it's alpha.
Z.
Use one of the macros in <ctype.h>
isalpha(char) is the best choice
isnumber(), ispunctuation(), isalmostanyhtingyouwantocheckfor()
- made up the last one..... :D
edit ctype.h, or go into help and look up either ctype or isalpha
He posted this question in General VB too, so I think he wants a VB answer. Which makes me wonder why he posted in a C++ forum. :rolleyes:
Just as extra info, you can also use the API. (VB & C++).
IsCharAlpha
IsCharAlphaNumeric
And here are their prototypes (in VB :)):
VB Code:
Declare Function IsCharAlpha Lib "user32" Alias "IsCharAlphaA" (ByVal cChar As Byte) As Long Declare Function IsCharAlphaNumeric Lib "user32" Alias "IsCharAlphaNumericA" (ByVal cChar As Byte) As Long
You don't need API for this (in VB).
Code:If strFoo Like "[A-z]" Then...
But isn't the Like operator really really really slow?