This documentation is archived and is not being maintained.

Char.IsDigit Method (String, Int32)

.NET Framework 1.1

Indicates whether the character at the specified position in a specified string is categorized as a decimal digit.

[Visual Basic]
Overloads Public Shared Function IsDigit( _
   ByVal s As String, _
   ByVal index As Integer _
) As Boolean
public static bool IsDigit(
 string s,
 int index
public: static bool IsDigit(
 String* s,
 int index
public static function IsDigit(
   s : String,
 index : int
) : Boolean;


A String.
The character position in s.

Return Value

true if the character at position index in s is a decimal digit; otherwise, false.


Exception Type Condition
ArgumentNullException s is a null reference (Nothing in Visual Basic).
ArgumentOutOfRangeException index is less than zero or greater than the last position in s.


This method determines if a Char is a radix-10 digit. This contrasts with IsNumber, which determines if a Char is of any numeric Unicode category.

Character positions in a string are indexed starting from zero.

Valid digits are members of the following category in UnicodeCategory: DecimalDigitNumber.


[Visual Basic, C#, C++] The following sample demonstrates IsDigit.

[Visual Basic] 
Imports System

Module IsDigitSample

    Sub Main()

        Dim ch8 As Char
        ch8 = "8"c

        Console.WriteLine(Char.IsDigit(ch8))                    ' Output: "True"
        Console.WriteLine(Char.IsDigit("sample string", 6))     ' Output: "False"

    End Sub

End Module

using System;

public class IsDigitSample {
    public static void Main() {
        char ch = '8';

        Console.WriteLine(Char.IsDigit(ch));                    // Output: "True"
        Console.WriteLine(Char.IsDigit("sample string", 7));    // Output: "False"

#using <mscorlib.dll>
using namespace System;

int main() {
   char ch = '8';

   Console::WriteLine(Char::IsDigit(ch));                    // Output: "True"
   Console::WriteLine(Char::IsDigit("sample string", 7));    // Output: "False"

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

Char Structure | Char Members | System Namespace | Char.IsDigit Overload List | Boolean | IsNumber