In C#, Char.IsNumber() is a System.Char struct method which is used to check whether a Unicode character can be categorized as a number or not. Valid numbers will be the members of the UnicodeCategory.DecimalDigitNumber, UnicodeCategory.LetterNumber, or UnicodeCategory.OtherNumber category.
This method can be overloaded by passing different type and number of arguments to it.
- Char.IsNumber(Char) Method
- Char.IsNumber(String, Int32) Method
Note: The only difference between Char.IsDigit() and Char.IsNumber() method is that IsDigit() method will only check whether a Char is a radix-10 digit or not. While IsNumber() method will check whether a char is a decimal digit, numbers include characters, fractions, subscripts, superscripts, Roman numerals, currency numerators, and encircled numbers or not.
Char.IsNumber(Char) Method
This method is used to check whether the specified Unicode character matches number or not. If it matches then it returns True otherwise return False.
Syntax:
public static bool IsNumber(char ch);
Parameter:
ch: It is required Unicode character of System.char type which is to be checked.
Return Type: The method returns True, if it successfully matches any number, otherwise returns False. The return type of this method is System.Boolean.
Example:
using System;
class GFG {
static public void Main()
{
bool result;
char ch1 = '5' ;
result = Char.IsNumber(ch1);
Console.WriteLine(result);
char ch2 = 'c' ;
result = Char.IsNumber(ch2);
Console.WriteLine(result);
}
}
|
Char.IsNumber(String, Int32) Method
This method is used to check whether the specified string at specified position matches with any number or not. If it matches then it returns True otherwise returns False.
Syntax:
public static bool IsNumber(string str, int index);
Parameters:
Str: It is the required string of System.String type which is to be evaluate.
index: It is the position of character in string to be compared and type of this parameter is System.Int32.
Return Type: The method returns True if it successfully matches any number at the specified index in the specified string, otherwise returns False. The return type of this method is System.Boolean.
Exceptions:
- If the value of str is null then this method will give ArgumentNullException.
- If the index is less than zero or greater than the last position in str then this method will give ArgumentOutOfRangeException.
Example:
using System;
class GFG {
static public void Main()
{
bool result;
string str1 = "GeeksforGeeks" ;
result = Char.IsNumber(str1, 2);
Console.WriteLine(result);
string str2 = "geeks5forgeeks" ;
result = Char.IsNumber(str2, 5);
Console.WriteLine(result);
}
}
|
Reference: https://docs.microsoft.com/en-us/dotnet/api/system.char.IsNumber?view=netframework-4.7.2
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
01 Feb, 2019
Like Article
Save Article