Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to check whether a specified character exists in a string ?

How to check whether a specified character exists in a string ?

Scheduled Pinned Locked Moved C#
tutorialquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr Perfect
    wrote on last edited by
    #1

    Dear All, PLease let me know how to check whether a specified character exists in a text or ? I am validating Password and I want to make sure that the password must contain atleast one numeric(0 to 9) , one special character and one uppercase letter. thanx in advance

    B E R L 4 Replies Last reply
    0
    • M Mr Perfect

      Dear All, PLease let me know how to check whether a specified character exists in a text or ? I am validating Password and I want to make sure that the password must contain atleast one numeric(0 to 9) , one special character and one uppercase letter. thanx in advance

      B Offline
      B Offline
      Bekjong
      wrote on last edited by
      #2

      public static bool CheckForE(string s) { return s.Contains("e"); }

      Standards are great! Everybody should have one!

      1 Reply Last reply
      0
      • M Mr Perfect

        Dear All, PLease let me know how to check whether a specified character exists in a text or ? I am validating Password and I want to make sure that the password must contain atleast one numeric(0 to 9) , one special character and one uppercase letter. thanx in advance

        E Offline
        E Offline
        Ennis Ray Lynch Jr
        wrote on last edited by
        #3

        While abc.Contains("0"); ... abc.Contains("%"); May work it will be too slow.

        if(abc.Length > MIN_LENGTH){
        char c;
        for(int i=0;i<abc.length;i++){
        c = abc[i];
        if(!numberFound)
        numberFound = Char.IsNumber(c);
        if(!specialFound)
        specialFound = Char.IsSymbol(c);
        if(!upperFound)
        upperFound = Char.IsUpper(c);
        if(!lowerFound)
        lowerFound = Char.IsLower(c);
        if(numberFound && specialFound && upperFound && lowerFound){
        valid = true;
        break;
        }

        }
        

        }//end if


        File Not Found

        1 Reply Last reply
        0
        • M Mr Perfect

          Dear All, PLease let me know how to check whether a specified character exists in a text or ? I am validating Password and I want to make sure that the password must contain atleast one numeric(0 to 9) , one special character and one uppercase letter. thanx in advance

          R Offline
          R Offline
          Russell Jones
          wrote on last edited by
          #4

          use substring to pull out each character in turn and if the character is of a type set a flag so you know you've found it. at the end all flags should be set and you're ready to go. BTW you should also test for lowercase as you are assuming that Upper case is different from the norm. Russ -- modified at 10:01 Friday 30th March, 2007

          1 Reply Last reply
          0
          • M Mr Perfect

            Dear All, PLease let me know how to check whether a specified character exists in a text or ? I am validating Password and I want to make sure that the password must contain atleast one numeric(0 to 9) , one special character and one uppercase letter. thanx in advance

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Hi, String.IndexOfAny(char[]) can check for the presence of any of a collection of chars. and String.ToCharArray() may be useful too. :)

            Luc Pattyn [My Articles]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups