/**
* 修改字符串的字节长度
* @param s 字符串
* @param length 最大字节长度
* */
public static String changeByteLength(String s,int length){
if(s.getBytes().length>length){
byte[] oldBytes = s.getBytes();
byte[] newBytes = new byte[length];
for (int i = 0; i < newBytes.length; i++) {
newBytes[i] = oldBytes[i];
}
String s2 = new String(newBytes);
s2 = String.copyValueOf(s2.toCharArray(),0,newBytes.length);
return s2;
}
return s;
}
修改字符串的字节长度
最新推荐文章于 2023-04-12 08:00:00 发布