Indicates whether the specified Unicode character is categorized as a letter or a decimal digit.
Assembly: mscorlib (in mscorlib.dll)
Public Shared Function IsLetterOrDigit ( _ c As Char _ ) As Boolean
public static bool IsLetterOrDigit( char c )
public: static bool IsLetterOrDigit( wchar_t c )
static member IsLetterOrDigit : c:char -> bool
Parameters
- c
- Type: System.Char
The Unicode character to evaluate.
Valid letters and decimal digits are members of the following categories in UnicodeCategory: UppercaseLetter, LowercaseLetter, TitlecaseLetter, ModifierLetter, OtherLetter, or DecimalDigitNumber.
The following code example demonstrates IsLetterOrDigit.
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
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 } }
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 }
.NET Framework
Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0.NET Framework Client Profile
Supported in: 4, 3.5 SP1Portable Class Library
Supported in: Portable Class LibraryWindows 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.
Reference
Char.IsLetterOrDigit('Ѝ')
returns
true
, because that's a letter in the Cyrillic alphabet
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