hi,
what variable should I use for JUST letters, just the 26 letters of the alphabet. No symbols, no numbers etc. I thought of using char, but that includes symbols. Or is there any other way to make an error come up if a letter is not inputted?
I dont really want to do:
If (Letter <> a) and (Letter <> b) and (Letter <> c) .... (Letter <> z) and (Letter <> A) and (Letter <> B) and (Letter <> C) .... (Letter <> Z)
then writeln ('Error');
Thanks
Try using regular expressions. Either filter out all a-z characters and see if the length is greater than 0 - or do a match or filter out all but a-z etc depending on what you want.
Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns
Virtually all languages (including Pascal descendants) use ASCII or Unicode for storing character information. If you want a subset of those characters, such as the upper/lowercase letters in the English alphabet, you need to create a filter. If you know your encoding, you can often do something like:
Code:if not (((letter >= 'a') and (letter <='z')) or ((letter >= 'A') and (letter <='Z'))) then writeln('Error');
Thanks for that Winged PantherForgot you can use > and < for letters. Thanks to the other guy too, but I didn't really understand lol.
Even if you don't use my method learning regular expressions will GREATLY help your programming knowledge in the future.
Good luck!
For the English alphabet use:
Code:Letter:=UpperCase(Letter); //'a'=>'A' if (Ord(Letter)<64) or (Ord(Letter)>90) then showmessage('Error.');
Last edited by Jaan; 12-13-2009 at 12:25 PM. Reason: Please use code tags when you are posting your codes!
Try this
This should let you filter out any charecters that are not in the alphabetCode:Var Letter: Char; if Not (Letter in ['a'..'z','A'..'Z']) then ShowMessage('Error.')
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks