How do I make a code in CS identify if the user input had letters or numbers? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do I make a code in CS identify if the user input had letters or numbers?

7th Dec 2019, 4:27 PM
Daniel Melo
Daniel Melo - avatar
2 Answers
+ 3
The Char-type has lots of methods that will tell you if a particular char is a number or a character. try Char.IsNumber(your char) Char.IsLetter(your char) So loop through the user-input, get single chars and check with these functions https://docs.microsoft.com/en-us/dotnet/api/system.char.isletter?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.char.isnumber?view=netframework-4.8 https://www.geeksforgeeks.org/c-sharp-char-isdigit-method/
7th Dec 2019, 8:44 PM
sneeze
sneeze - avatar
+ 2
I think , easiest way it look ASCII table, get HEX codes for chars and numbers, and then write if-else comparator.
7th Dec 2019, 7:57 PM
id001x
id001x - avatar