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 / C++ / MFC
  4. string manipulation question

string manipulation question

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomtutorial
14 Posts 7 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
    monsieur_jj
    wrote on last edited by
    #1

    Hi all, How do I know the number of occurences of a character from a string for example the "@" sign from email@email@email.com. I need to validate email addresses. Thanks, Jayjay

    M R CPalliniC D 4 Replies Last reply
    0
    • M monsieur_jj

      Hi all, How do I know the number of occurences of a character from a string for example the "@" sign from email@email@email.com. I need to validate email addresses. Thanks, Jayjay

      M Offline
      M Offline
      Michael Schubert
      wrote on last edited by
      #2

      Count them. Seriously though, are you kidding? After more than a year of asking programming questions here you can't figure this out by yourself? You should consider a career change.

      modified on Thursday, October 16, 2008 5:29 AM

      R S 2 Replies Last reply
      0
      • M monsieur_jj

        Hi all, How do I know the number of occurences of a character from a string for example the "@" sign from email@email@email.com. I need to validate email addresses. Thanks, Jayjay

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #3

        monsieur_jj wrote:

        I need to validate email addresses.

        You need to validate the email address to have one and only one '@' character? OK, this code will do that:

        const char *szEmail= "myname@mydoma@in.com";
        strchr(szEmail,'@')?strchr(strchr(szEmail,'@')+1,'@')?cout<<"Invalid!":cout<<"Valid!":cout<<"Invalid!!";

        Program Output: Invalid! Error checking and any dodgy stuff must be handled by *you* of course. :-\

        Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

        1 Reply Last reply
        0
        • M monsieur_jj

          Hi all, How do I know the number of occurences of a character from a string for example the "@" sign from email@email@email.com. I need to validate email addresses. Thanks, Jayjay

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          Call iteratively strchr [^]. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          1 Reply Last reply
          0
          • M Michael Schubert

            Count them. Seriously though, are you kidding? After more than a year of asking programming questions here you can't figure this out by yourself? You should consider a career change.

            modified on Thursday, October 16, 2008 5:29 AM

            R Offline
            R Offline
            Rajesh R Subramanian
            wrote on last edited by
            #5

            Michael Schubert: CodeProject's official career counselor. :laugh:

            Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

            M 1 Reply Last reply
            0
            • M Michael Schubert

              Count them. Seriously though, are you kidding? After more than a year of asking programming questions here you can't figure this out by yourself? You should consider a career change.

              modified on Thursday, October 16, 2008 5:29 AM

              S Offline
              S Offline
              SandipG
              wrote on last edited by
              #6

              Michael Schubert wrote:

              You should consider a career change.

              Any suggestions??

              Regards, Sandip.

              M CPalliniC 2 Replies Last reply
              0
              • R Rajesh R Subramanian

                Michael Schubert: CodeProject's official career counselor. :laugh:

                Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

                M Offline
                M Offline
                Michael Schubert
                wrote on last edited by
                #7

                He he. I think not. John Simmons is much better at that. ;)

                1 Reply Last reply
                0
                • S SandipG

                  Michael Schubert wrote:

                  You should consider a career change.

                  Any suggestions??

                  Regards, Sandip.

                  M Offline
                  M Offline
                  Michael Schubert
                  wrote on last edited by
                  #8

                  This could get ugly. Maybe switching to Visual Basic?

                  C 1 Reply Last reply
                  0
                  • M Michael Schubert

                    This could get ugly. Maybe switching to Visual Basic?

                    C Offline
                    C Offline
                    Cedric Moonen
                    wrote on last edited by
                    #9

                    Michael Schubert wrote:

                    Maybe switching to Visual Basic?

                    Oh my God... You are the worst job counselor I have ever seen :rolleyes:

                    Cédric Moonen Software developer
                    Charting control [v1.5] OpenGL game tutorial in C++

                    M 1 Reply Last reply
                    0
                    • C Cedric Moonen

                      Michael Schubert wrote:

                      Maybe switching to Visual Basic?

                      Oh my God... You are the worst job counselor I have ever seen :rolleyes:

                      Cédric Moonen Software developer
                      Charting control [v1.5] OpenGL game tutorial in C++

                      M Offline
                      M Offline
                      Michael Schubert
                      wrote on last edited by
                      #10

                      I know. ;P

                      1 Reply Last reply
                      0
                      • S SandipG

                        Michael Schubert wrote:

                        You should consider a career change.

                        Any suggestions??

                        Regards, Sandip.

                        CPalliniC Offline
                        CPalliniC Offline
                        CPallini
                        wrote on last edited by
                        #11

                        Yes, of course [^]. :-D

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                        [My articles]

                        In testa che avete, signor di Ceprano?

                        S 1 Reply Last reply
                        0
                        • CPalliniC CPallini

                          Yes, of course [^]. :-D

                          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                          [My articles]

                          S Offline
                          S Offline
                          SandipG
                          wrote on last edited by
                          #12

                          That is interesting .. May be it will suit him.. BTW: Looks like this is another crime of THHB. :D

                          Regards, Sandip.

                          CPalliniC 1 Reply Last reply
                          0
                          • S SandipG

                            That is interesting .. May be it will suit him.. BTW: Looks like this is another crime of THHB. :D

                            Regards, Sandip.

                            CPalliniC Offline
                            CPalliniC Offline
                            CPallini
                            wrote on last edited by
                            #13

                            SandipG :) wrote:

                            BTW: Looks like this is another crime of THHB.

                            Another one here [^]. :-D

                            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                            [My articles]

                            In testa che avete, signor di Ceprano?

                            1 Reply Last reply
                            0
                            • M monsieur_jj

                              Hi all, How do I know the number of occurences of a character from a string for example the "@" sign from email@email@email.com. I need to validate email addresses. Thanks, Jayjay

                              D Offline
                              D Offline
                              David Crow
                              wrote on last edited by
                              #14

                              You could try:

                              string strEmail = "email@email@email.com";
                              count(strEmail.begin(), strEmail.end(), '@');

                              "Love people and use things, not love things and use people." - Unknown

                              "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                              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