public class JieQuStr {
private String str;
private int byteNum;
public JieQuStr(String str, int byteNum) {
this.str = str;
this.byteNum = byteNum;
}
public void splitIt() {
byte bt[] = str.getBytes();
System.out.println("Length of this String ===>" + bt.length);
if (bt[byteNum] <0) {
String substrx = new String(bt, 0, --byteNum);
System.out.println(substrx);
} else {
String substrex = new String(bt, 0, byteNum);
System.out.println(substrex);
}
}
public static void main(String[] args) {
String str = "我ABC汉DEF";
int num = 7;
JieQuStr sptstr = new JieQuStr(str, num);
sptstr.splitIt();
}
}
截取汉字
最新推荐文章于 2024-05-08 07:00:56 发布