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 á?
We can check whether the given character in a string is a number/letter by using isDigit() method of Character class.
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.
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”.
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) ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With