Checks if a string contains only letters - CSharp System

CSharp examples for System:String Contain

Description

Checks if a string contains only letters

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Globalization;
using System.Collections.Generic;
using System;//from w w  w.j a  v  a2  s.  co m

public class Main{
        //Checks if a string contains only letters
        //Hi -> True
        //Hi123 -> False
        public static bool isLetters(string input)
        {
            char currentLetter;
            for (int i = 0; i < input.Length; i++)
            {
                currentLetter = input[i];

                if (!(Convert.ToInt32(currentLetter) >= 65 && Convert.ToInt32(currentLetter) <= 90) &&
                    !(Convert.ToInt32(currentLetter) >= 97 && Convert.ToInt32(currentLetter) <= 122))
                {
                    //Not a letter
                    return false;
                }
            }
            return true;
        }
}

Related Tutorials