The method in c that determines whether a string is a number or a letter

  • 2020-05-12 03:13:41
  • OfStack

1. Judge the letters

string str = Console.ReadLine();
if (char.isLetter(str))
{
}
else if (char.IsDigit(str))
{
}

if(ch > ='a'&&ch < ='z') lowercase letters
if(ch > ='A'&&ch < ='Z') capital letters
The number is also one.
Judge Chinese character 1 as input > 255 because Chinese characters are large character sets
2. Determine if the input is a number

try
{
int n = 0;
n = int.Parse(this.textBox1.Text.Trim());
}
catch
{
MessageBox.Show(" You're not typing a number ~!");
}

You can also use Char.isNumber (str[i]) for each character.

Related articles: