Just use the replace method of the C++ string class.
Something like this perhaps.
#include <iostream>
#include <string>
int main()
{
std::string email("abcdefgh@abcd.com");
std::cout << email << std::endl;
email.replace( email.find('@'),1, "AT" );
std::cout << email << std::endl;
return 0;
}
One thing to note is that only the first @ character will be replaced by this method. But I think a string with multiple @ characters is not a valid email address.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
How can I get a program to find and extract an email adress from a line and replaces the @ sign with 'AT'?
1) Search for the @
2) test characters after the @ for valid domain name construct. Memorize the first position that doesn't fit.
3) test the characters before the @ for valid email name construct. Memorize the first position that doesn't fit.
4) Copy all the characters between the memorized positions. I just started learning c++ and have run into a wall. I can get my screen to display everyhing from the @ sign to the end of the string, but I cant get it to stop at the.com or the space right after.
Why not? What are you doing wrong?I just need to see a solution or possible a different aproach, thanks!
Actually, what you need is to show us what you are doing and maybe we canhelp you fix it.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944