C# | Char.IsNumber() Method
Last Updated :
01 Feb, 2019
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:
CSHARP
// C# program to illustrate the
// Char.IsNumber(Char) Method
using System;
class GFG {
// Main Method
static public void Main()
{
// Declaration of data type
bool result;
// checking if 5 is a
// number or not
char ch1 = '5';
result = Char.IsNumber(ch1);
Console.WriteLine(result);
// checking if 'c' is a
// number or not
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:
CSHARP
// C# program to illustrate the
// Char.IsNumber(String, Int32) Method
using System;
class GFG {
// Main Method
static public void Main()
{
// Declaration of data type
bool result;
// checking for number in a
// string at a desired position
string str1 = "GeeksforGeeks";
result = Char.IsNumber(str1, 2);
Console.WriteLine(result);
// checking for number in a
// string at a desired position
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
Similar Reads
C# | Char.ConvertFromUtf32(Int32) Method This method is used to converts the specified Unicode code point into a UTF-16 encoded string.Syntax: public static string ConvertFromUtf32 (int utf32); Here, utf32 is a 21-bit Unicode code point.Return Value: This method returns a string consisting of one Char object or a surrogate pair of Char obj
2 min read
C# | Char.Equals() Method In C#, Char.Equals() is a System.Char struct method which is used to return a value by checking whether current instance is equal to a specified object or Char value. This method can be overloaded by passing different type of arguments to it. Char.Equals(Char) Method Char.Equals(Object) Method Char.
3 min read
C# | Char.GetHashCode() Method with Examples This method is used to return the hash code for this instance. Syntax: public override int GetHashCode (); Return Value: This method returns a 32-bit signed integer hash code. Below programs illustrate the use of Char.GetHashCode() Method: Example 1: csharp // C# program to demonstrate // Char.GetHa
1 min read
C# | Char.GetNumericValue() Method In C#, Char.GetNumericValue() is a System.Char struct method which is used to convert a numeric Unicode character into a double-precision floating-point number. The numeric value must belong to UnicodeCategory, i.e DecimalDigitNumber, LetterNumber, or OtherNumber. This method can be overloaded by pa
2 min read
C# | Char.GetTypeCode() Method with Examples This method is used to return the TypeCode for value type Char. Syntax: public TypeCode GetTypeCode (); Return Value: This method returns the enumerated constant, Char.Below programs illustrate the use of Char.GetTypeCode() Method:Example 1: csharp // C# program to demonstrate // Char.GetTypeCode()
2 min read
C# | Char.GetUnicodeCategory(String, Int32) Method with Examples This method is used to categorizes the character at the specified position in a specified string into a group identified by one of the UnicodeCategory values. Syntax: public static System.Globalization.UnicodeCategory GetUnicodeCategory (string s, int index); Parameters: s: It is the String.index: I
3 min read
C# | Char.IsControl(String, Int32) Method This method is used to indicates whether the character at the specified position in a specified string is categorized as a control character. Syntax: public static bool IsControl (string s, int index); Parameters: s: It is the String. index: It is the character position in s. Return Value: This meth
3 min read
C# | Char.IsDigit() Method In C#, Char.IsDigit() is a System.Char struct method which is used to check whether a Unicode character can be categorized as a decimal digit(radix 10) or not. Valid digits will be the members of the UnicodeCategory.DecimalDigitNumber category. This method can be overloaded by passing different type
3 min read
C# | Char.IsHighSurrogate(String, Int32) Method This method is used to indicates whether the Char object at the specified position in a string is a high surrogate or not. Syntax: public static bool IsHighSurrogate (string s, int index); Parameters: s: It is a String. index: It is the character position in s. Return Value: This method returns true
4 min read
C# | Char.IsLetter() Method In C#, Char.IsLetter() is a System.Char struct method which is used to check whether a Unicode character can be categorized as a Unicode letter or not. Unicode letters consist of the Uppercase letters, Lowercase letters, Title case letters, Modifiers letters and Other letters. This method can be ove
3 min read