Skip to content
Loading
How to find Upper Case Letter in String
  •  bool IsAllUpper(string input)
    {
    for (int i = 0; i < input.Length; i++)
    {
    if (Char.IsLetter(input[i]) && Char.IsUpper(input[i]))
    return true;
    }
    return false;
    }

    it work also special character or digit in input string

    above code helps you to make it working.
    0
  • Lokesh Kumar
    Hi Friend,
    Please try this:-
    protected void CustV1_ServerValidate(object source, ServerValidateEventArgs args)
    {
    foreach(char c in args.Value)
    {
    if (Char.IsUpper(c))
    {
    args.IsValid = true;
    break;
    }
    }
    args.IsValid = false;
    }
    0
  • Hussain Patel
    if you wantto find the upper case character in args.Valueyou will have to loopto the each character of args.Valueusing foreach loop and if you get any UpperCase character exit out of foreach loop and then use the if condition you have..
    Here is the sample code..
    1. classProgram
    2. {
    3. staticvoidMain(string[]args)
    4. {
    5. stringinputString="WelcometoAbundantCode!!!";
    6. booltmp=false;
    7. foreach(charxininputString)//replaceinputstringwithargs.Value
    8. {
    9. if(Char.IsLower(x))
    10. tmp=false;
    11. elseif(Char.IsUpper(x))
    12. tmp=true;
    13. }
    14. if(tmp)
    15. {
    16. //CustV1.IsValid=true;
    17. }
    18. Console.Read();
    19. }
    20. }
    Hope this helps..
    0
  • Just go through following links
    http://stackoverflow.com/questions/6195270/what-is-the-fastest-way-to-check-whether-string-has-uppercase-letter-in-c
    http://stackoverflow.com/questions/20032450/detect-if-a-string-contains-uppercase-characters
    0
  • Vulpes
    OK, here's the code for both:

    /* checking for at least one upper case character

    protected void CustV1_ServerValidate(object source, ServerValidateEventArgs args)
         foreach(char c in args.Value)
         {
            if (Char.IsUpper(c))
            {
               args.IsValid = true;
               return;
            }
         }

         args.IsValid = false;
    }

    /* checking for ALL upper case characters

    protected void CustV1_ServerValidate(object source, ServerValidateEventArgs args)
         foreach(char c in args.Value)
         {
            if (!Char.IsUpper(c))
            {
               args.IsValid = false;
               return;
            }
         }

         args.IsValid = true;
    }

    0
  • Vulpes
    Do you mean that you want to check that at least one character in args.Value is an upper case letter or that ALL characters in that string are upper case letters?
    0