简体   繁体   中英

How can I mask the first 4 digits of a stringed number

我想屏蔽字符串的前4位数字,例如1234567看起来像**** 567

You can use the substring function. Try something like that

 String number=1234567;
 String maskNumber="****"+number.substring(4);

怎么样:

"12345654".replaceFirst("[0-9]{4}", "****");

You could to this:

String str = "1234567";
String firstFourChars = str.substring(0, 4);
String newStr = str.replaceFirst(firstFourChars, "****");

Or to make it shorter:

str = str.replaceFirst(str.substring(0, 4), "****");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM