I have a SSN inputed by the user. What is the best way to added dashes to that number before I display it back on the screen?
input 123456789
output needs to look like 123-45-6789
Thanks,
I have a SSN inputed by the user. What is the best way to added dashes to that number before I display it back on the screen?
input 123456789
output needs to look like 123-45-6789
Thanks,
This little program should give you the idea :
Code:#include <iostream> #include <string> using namespace std; string makeformat(string oldstring) { string answer; answer = oldstring.substr(0, 3) + "-" + oldstring.substr(3,2) + "-" + oldstring.substr(5, 4); return answer; } int main() { string string1 = "123456789"; string newstring; newstring = makeformat(string1); cout << newstring << endl; return 0; }
Last edited by moonwalker; 07-11-2003 at 07:39 AM.
Thanks, that worked.