截取包含中文的字符串

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));
}

猜你喜欢

转载自blog.csdn.net/processengine/article/details/8169223