Java掩码的几种使用例举
java掩码
privatestaticStringnameMask(Stringname)throwsException{ if(name==null)thrownewException("请输入要掩码的字符串"); if(name.length()<=1)returnname+"*"; returnname.replaceAll("([\\u4e00-\\u9fa5]{1})(.*)","$1"+createAsterisk(name.length()-1)); } privatestaticStringcreateAsterisk(intlen){ StringBuffersb=newStringBuffer(); for(inti=0;i /** *对客户证件号码做掩码 * **/ publicstaticStringmaskCertId(StringcertId)throwsException { if(certId==null||certId.length()==0)return""; if(certId.length()==18) { Stringv=certId.substring(0,4); Stringend=certId.substring(certId.length()-4); returnv+StringUtils.repeat("*",8)+end; } else return""; }/** *对客户姓名做掩码 *@throwsJBOException **/ publicstaticStringmaskUserName(StringuserName)throwsException { if(userName==null||userName.length()==0)return""; Stringv=userName.substring(0,1); returnStringUtils.rightPad(v,userName.length(),"*");//StringUtils.rightPad方法做一个字符串右补齐 }/** *对字符串进行脱敏处理 *@paramword被脱敏的字符 *@paramstartLength被保留的开始长度0代表不保留 *@paramendLength被保留的结束长度0代表不保留 *@parampad填充字符 **/ publicstaticStringwordMask(Stringword,intstartLength,intendLength,Stringpad){ if(word==null)returnStringUtils.leftPad("",startLength+endLength,pad); if(word.length()<=startLength+endLength)returnStringUtils.leftPad("",startLength+endLength,pad); StringstartStr=""; StringendStr=""; intpadLength=0; if(word.length()>startLength)startStr=StringUtils.substring(word,0,startLength); if(word.length()>startLength+endLength)endStr=StringUtils.substring(word,word.length()-endLength); padLength=word.length()-startLength-endLength; returnstartStr+StringUtils.repeat(pad,padLength)+endStr; }总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对毛票票的支持。如果你想了解更多相关内容请查看下面相关链接