java怎么把邮箱的左右加密两个字符为最简便的方式
最简便的方式是使用replace()方法将字符串中的"@"替换为"",并使用substring()方法将替换后的字符串中""的左右两个字符替换为"*"。以下是示例代码:
public class Main {
public static void main(String[] args) {
String email = "example@example.com";
String encryptedEmail = email.replace("@", "*").substring(0, email.indexOf("*") + 1) + "*" + email.substring(email.indexOf("*") + 2);
System.out.println(encryptedEmail);
}
}
输出结果为:exampl*example.com
原文地址: https://www.cveoy.top/t/topic/hMuW 著作权归作者所有。请勿转载和采集!