string manipulation question
-
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
-
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
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
-
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
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++]
-
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
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] -
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
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++]
-
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
-
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++]
He he. I think not. John Simmons is much better at that. ;)
-
Michael Schubert wrote:
You should consider a career change.
Any suggestions??
Regards, Sandip.
This could get ugly. Maybe switching to Visual Basic?
-
This could get ugly. Maybe switching to Visual Basic?
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++ -
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++I know. ;P
-
Michael Schubert wrote:
You should consider a career change.
Any suggestions??
Regards, Sandip.
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] -
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] -
That is interesting .. May be it will suit him.. BTW: Looks like this is another crime of THHB. :D
Regards, Sandip.
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] -
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
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