0

What are some different ways I can modify a string holding ssn so that

123-45-8999 becomes XXX-XX-8999 ?

Must use string member functions to accomplish this.

Thanks!

Tex Qas
  • 371
  • 1
  • 3
  • 4

1 Answers1

2

Try replace:

std::string s = "123-45-8999";

s.replace(0, 6, "XXX-XX");

If the field widths are dynamic, you can combine this idea with the string tokenization we did just earlier to get something more flexible.

Community
  • 1
  • 1
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084