Char.IsLetterOrDigit Method (Char) (System)

Switch View :
ScriptFree
.NET Framework Class Library
Char.IsLetterOrDigit Method (Char)

Indicates whether the specified Unicode character is categorized as a letter or a decimal digit.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
Syntax

Visual Basic
Public Shared Function IsLetterOrDigit ( _
	c As Char _
) As Boolean
C#
public static bool IsLetterOrDigit(
	char c
)
Visual C++
public:
static bool IsLetterOrDigit(
	wchar_t c
)
F#
static member IsLetterOrDigit : 
        c:char -> bool 

Parameters

c
Type: System.Char
The Unicode character to evaluate.

Return Value

Type: System.Boolean
true if c is a letter or a decimal digit; otherwise, false.
Remarks

Valid letters and decimal digits are members of the following categories in UnicodeCategory: UppercaseLetter, LowercaseLetter, TitlecaseLetter, ModifierLetter, OtherLetter, or DecimalDigitNumber.

Examples

The following code example demonstrates IsLetterOrDigit.

Visual Basic

imports System

Module IsLetterOrDigitSample

    Sub Main()

        Dim str As String
        str = "newline:" + vbNewLine

        Console.WriteLine(Char.IsLetterOrDigit("8"c))       ' Output: "True"
        Console.WriteLine(Char.IsLetterOrDigit(str, 8))     ' Output: "False", because it's a NewLine

    End Sub

End Module


C#

using System;

public class IsLetterOrDigitSample {
	public static void Main() {
		string str = "newline:\n";

		Console.WriteLine(Char.IsLetterOrDigit('8'));		// Output: "True"
		Console.WriteLine(Char.IsLetterOrDigit(str, 8));	// Output: "False", because it's a newline
	}
}


Visual C++

using namespace System;
int main()
{
   String^ str =  "newline:\n";
   Console::WriteLine( Char::IsLetterOrDigit( '8' ) ); // Output: "True"
   Console::WriteLine( Char::IsLetterOrDigit( str, 8 ) ); // Output: "False", because it's a newline
}



Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also

Reference

Community Content

Shital Shah
It's not just a-zA-Z0-9
Char.IsLetterOrDigit('Ѝ')  returns  true , because that's a letter in the Cyrillic alphabet

R Petrusha - MSFT
AM i Correct ?
imports System

Module IsLetterOrDigitSample

Sub Main()

Dim str AsString
str = "newline:" + vbNewLine

Console.WriteLine(Char.IsLetterOrDigit("8"c)) ' Output: "True"
Console.WriteLine(Char.IsLetterOrDigit(str, 8)) ' Output: "False", because it's a NewLine
'From Programista 'I think the colon (:) makes the output False.
EndSub

End Module


I'm not sure what you mean by "makes the output False". But you can modify the example somewhat to evaluate each character in a string:

Module IsLetterOrDigitSample
Sub Main()
Dim str As String
str = "newline:" + vbNewLine

For Each ch In str
Console.WriteLine("'{0}' (0x{2:X4})': {1}",
If(ch >= "!", ch, ""),
Char.IsLetterOrDigit(ch),
Convert.ToUInt16(ch))
Next
End Sub
End Module


This displays the following output:

'n' (0x006E)': True
'e' (0x0065)': True
'w' (0x0077)': True
'l' (0x006C)': True
'i' (0x0069)': True
'n' (0x006E)': True
'e' (0x0065)': True
':' (0x003A)': False
'' (0x000D)': False
'' (0x000A)': False


--Ron Petrusha
Common Language Runtime Developer Content
Microsoft Corporation