How to mask SSN in a string ?
I am have the following scenario
string str1 = "asdasfasdfasdf sfhagfdad SSN:123456789";
my required output "asdasfasdfasdf sfhagfdad SSN:*********"
I tried the below code
Regex ssnRegex = new Regex("(?:\bSSN:\b)(?:[0-9]{3})(?:[0-9]{2})(?:[0-9]{4})");
string formattedSSN = ssnRegex.Replace(t1, "SSN:-XXX-XX-XXXX");
I think i am missing to capture “SSN:” Could you please tell me how to get the above output
Why not just use
String.Replace?