截取包含中文的字符串

来源:互联网 发布:沂南知豆租赁电话 编辑:程序博客网 时间:2024/05/04 23:38
public byte[] sub(byte[] byt, int len)
{
return Arrays.copyOf(byt, len);
}

public byte[] sub(byte[] byt, int from, int to)
{
return Arrays.copyOfRange(byt, from, to);
}

public String sub(String str, int len)
{
byte[] byt = str.getBytes();
byte[] b = this.sub(byt, len);
String last = new String(this.sub(b, len - 1, len));
String end = new String(this.sub(b, len - 2, len));
if ((b[len - 1] < 0 && str.contains(end)) || str.contains(last)) return new String(
b);
else return new String(this.sub(b, len - 1));
}
原创粉丝点击