Maybe I'm missing something obvious, but is there a simpler way to check if a character is a basic latin letter (a-z) other than converting to a string and using Regex?: For example:
public static bool IsBasicLetter(Char c) {
return Regex.IsMatch(c.ToString(), "[a-z]", RegexOptions.IgnoreCase);
}
Char.IsLetter matches hundreds of letter characters from many alphabets. I could directly check the code points, but that feels sketchy:
public static bool IsBasicLetter(Char c) {
int cInt = c;
return !(cInt < 65 || cInt > 122 || (cInt > 90 & cInt < 97));
}
To check if a string contains only latin characters, use the test() method with the following regular expression /^[a-zA-Z]+$/ . The test method will return true if the string contains only latin characters and false otherwise.
The ISO basic Latin alphabet is composed of 26 uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ) and 26 lowercase versions of the same letters (abcdefghijklmnopqrstuvwxyz), resulting in the following pairs: Aa Bb Cc Dd Ee Ff Gg Hh Ii Jj Kk Ll Mm Nn Oo Pp Qq Rr Ss Tt Uu Vv Ww Xx Yy Zz.
There were no lowercase letters. ABCDEFGHIJKLM. NOPQRSTUVWXYZ. For phonetic reasons, the symbols “J”, “U” and “W” were added to our alphabet during the Middle Ages. The Latin language used an “I” symbol where we use a “J”, a “V” symbol where we use a “U”.
Classic Latin is written using the same alphabet as English. There are many other languages that use this alphabet, including Spanish, Italian, and French—although other languages use accent marks that aren't used for English or Latin. In practice, some letters aren't used to spell Latin words, such as "j" and "k."
Your second bit of code looks a lot better if you use character literals:
public static bool IsBasicLetter(char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}
How about this?
return (x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z');
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