Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check if the character is an integer

Tags:

c#

People also ask

How do you check if a character is an integer Python?

In Python, we may use the isdigit() function to see if a string is an integer or not. The isdigit() procedure will give True if the characters in a string are digits.

How do you check if a string is an integer?

To check if a string is integer in Python, use the isdigit() method. The string isdigit() is a built-in Python method that checks whether the given string consists of only digits.

Can a character be an integer?

Yes, a char is an integral type in all the popular languages in which it appears. "Integral" means that its spectrum is discrete and the smallest difference between any two distinct values is 1 .

How do you check if a character is an integer in JavaScript?

The Number. isInteger() method in JavaScript is used to check whether the value passed to it is an integer or not. It returns true if the passed value is an integer, otherwise, it returns false.


Use System.Char.IsDigit method


If you want just the pure 0-9 digits, use

if(a>='0' && a<='9')

IsNumeric and IsDigit both return true for some characters outside the 0-9 range:

Difference between Char.IsDigit() and Char.IsNumber() in C#


Integer.TryParse works well.

http://msdn.microsoft.com/en-us/library/f02979c7.aspx


The bool Char.IsDigit(char c); Method should work perfectly for this instance.

char a = '1';

if (Char.IsDigit(a))
{
  //do something
}

Try using System.Char.IsDigit method.


Try Char.IsNumber. Documentation and examples can be found here