Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨,我有一个信用卡号作为字符串。我需要应用掩码来隐藏 CC 编号:
我有“123-123-123”,我需要得到类似“123-XXX-123”的东西
有什么优雅的方法可以做到这一点吗?我试图避免使用几个 substring() 函数......
提前致谢
myCCStr = myCCStr.replaceFirst("-[0-9]{3}-", "-XXX-");
我相信您可以使用 String 类的 PADLeft 和 PADRight 函数来实现这一点。