C# | Char.IsLetter() Method (original) (raw)

Last Updated : 31 Jan, 2019

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 overloaded by passing different type and number of arguments to it. 1. Char.IsLetter(Char) Method 2. Char.IsLetter(String, Int32) Method

Char.IsLetter(Char) Method

This method is used to check whether the specified Unicode character matches Unicode letter or not. If it matches then it returns True otherwise return False.Syntax:

public static bool IsLetter(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 Unicode letter, otherwise returns False. The return type of this method is System.Boolean.Example:

CSHARP `

// C# program to illustrate the // Char.IsLetter(Char) Method using System;

class GFG {

// Main Method
static public void Main()
{

    // Declaration of data type
    bool result;

    // checking if G is a
    // Unicode letter or not
    char ch1 = 'G';
    result = Char.IsLetter(ch1);
    Console.WriteLine(result);

    // checking if '6' is a
    // Unicode letter or not
    char ch2 = '6';
    result = Char.IsLetter(ch2);
    Console.WriteLine(result);
}

}

`

Char.IsLetter(String, Int32) Method

This method is used to check whether the specified string at specified position matches with any Unicode letter or not. If it matches then it returns True otherwise returns False.Syntax:

public static bool IsLetter(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 Unicode letter at the specified index in the specified string, otherwise returns False. The return type of this method is System.Boolean.Exceptions:

Example:

CSHARP `

// C# program to illustrate the // Char.IsLetter(String, Int32) Method using System;

class GFG {

// Main Method
static public void Main()
{

    // Declaration of data type
    bool result;

    // checking for Unicode letter in
    // a string at a desired position
    string str1 = "GeeksforGeeks";
    result = Char.IsLetter(str1, 2);
    Console.WriteLine(result);

    // checking for Unicode letter in a
    // string at a desired position
    string str2 = "geeks46forgeeks";
    result = Char.IsLetter(str2, 5);
    Console.WriteLine(result);
}

}

`

Reference: https://docs.microsoft.com/en-us/dotnet/api/system.char.IsLetter?view=netframework-4.7.2