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!

4

1 回答 1

2

尝试replace

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

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

如果字段宽度是动态的,您可以将这个想法与我们之前所做的字符串标记化结合起来,以获得更灵活的东西。

于 2012-10-28T23:31:41.773 回答