How to check if a String contains any letter from a to z? [duplicate] How to check if a String contains any letter from a to z? [duplicate] windows windows

How to check if a String contains any letter from a to z? [duplicate]


What about:

//true if it doesn't contain lettersbool result = hello.Any(x => !char.IsLetter(x));


Replace your for loop by this :

errorCounter = Regex.Matches(yourstring,@"[a-zA-Z]").Count;

Remember to use Regex class, you have to using System.Text.RegularExpressions; in your import


You could use RegEx:

Regex.IsMatch(hello, @"^[a-zA-Z]+$");

If you don't like that, you can use LINQ:

hello.All(Char.IsLetter);

Or, you can loop through the characters, and use isAlpha:

Char.IsLetter(character);