Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use regex from the standard library.</p> <pre><code>#include &lt;regex&gt; using namespace std::tr1; </code></pre> <p>I haven't played with C++ in many years, but it would be something like this (assuming you stored your string in the variable 'str'):</p> <pre><code>std::tr1::regex rx("[0-9]..-..-"); std::string replacement = "***-**-"; std::string str2 = std::tr1::regex_search(str, rx, replacement); </code></pre> <p>The above code was referenced from <a href="http://www.johndcook.com/cpp_regex.html" rel="nofollow noreferrer">this site</a>, and you can test your regular expressions with this <a href="http://rubular.com/" rel="nofollow noreferrer">fantastic tool</a>. I am fairly certain that you want regex_search as opposed to regex_replace due to the slightly different way that C++ handles matches, but again, I haven't used C++ in some time, so I can't say for sure.</p> <p>Note that "[0-9]..-..-" is a regex that will match any numeric character followed by two characters of any type (. is a wildcard), then a -, then two more characters of any type, then another -. Thus, in your text, it will only match the first two segments of the two SSNs. You are then replacing the numbers in that matched pattern with asterisks.</p> <p>Also, being as this is homework, I'd like to give you some additional resources, with the first being language-specific:</p> <p><a href="http://softwareramblings.com/2008/07/regular-expressions-in-c.html" rel="nofollow noreferrer">http://softwareramblings.com/2008/07/regular-expressions-in-c.html</a></p> <p><a href="http://www.regular-expressions.info/reference.html" rel="nofollow noreferrer">http://www.regular-expressions.info/reference.html</a></p> <p><a href="http://www.zytrax.com/tech/web/regex.htm" rel="nofollow noreferrer">http://www.zytrax.com/tech/web/regex.htm</a></p> <p>Also, in the future, you will probably get more useful answers if you follow the <a href="https://meta.stackexchange.com/questions/10811/how-to-ask-and-answer-homework-questions">community guidelines for asking homework questions.</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload