开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜