How to apply a mask to a String?
Hi I have a credit card number as a String. I need to apply a mask开发者_开发百科 to hide the CC number:
I have "123-123-123" and I need to get something like "123-XXX-123"
Is there any elegant way to do this? I'm trying to avoid using severals substring() functions...
Thanks in advance
myCCStr = myCCStr.replaceFirst("-[0-9]{3}-", "-XXX-");
I believe you can achieve this using PADLeft and PADRight functions of String class.
精彩评论