Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if char isletter

Tags:

c#

.net

char

i want to check if a string only contains correct letters. I used Char.IsLetter for this. My problem is, when there are chars like é or á they are also said to be correct letters, which shouldn't be.

is there a possibility to check a char as a correct letter A-Z or a-z without special-letters like á?

like image 567
abc Avatar asked Apr 02 '12 11:04

abc


People also ask

How do you check if a char is a letter?

We can check whether the given character in a string is a number/letter by using isDigit() method of Character class.

How do you check if a character is a special character?

Special characters are those characters that are neither a letter nor a number. Whitespace is also not considered a special character. Examples of special characters are:- !( exclamation mark), , (comma), #(hash), etc.

How do you check if a char is a number Java?

You can use the Java built-in “isDigit()” method of the Character Class to validate whether a character is a number. It determines whether the given character is a digit or not and returns boolean values: “true” or “false”.


1 Answers

bool IsEnglishLetter(char c)
{
    return (c>='A' && c<='Z') || (c>='a' && c<='z');
}

You can make this an extension method:

static bool IsEnglishLetter(this char c) ...
like image 111
zmbq Avatar answered Sep 19 '22 05:09

zmbq