How to check the string for the presence of letters in a shorter way than just a search and a huge condition?
|
3 answers
This is simply solved using regular expressions.
Regex.IsMatch(test, "^[^x]+$");
test
- string to check^
- beginning of line[^x]
- all characters exceptx
+
- one or more occurrences$
- end of line
As a result, the string will be checked for the presence of the letter x
.
|
if (str.Any(c => char.IsLetter(c)))
|
take the first character if it is 0, neOK, if 1 - neOK, etc. =), if A - OK - is it long?
char.isLetter();
|