public class StringHanzi {
public static boolean isChineseChar(
char c)
throws UnsupportedEncodingException{
return String.
valueOf(c).getBytes(
"GBK").
length>
1;
}
public static String
cutString(String str
,int num){
char[] chars=str.toCharArray()
;
String s=
"";
int i=
0;
int count=
0;
while(i<num){
try {
if(
isChineseChar(chars[count])){
i=i+
2;
if(i<=num){
s=s+String.
valueOf(chars[count])
;
}
}
else{
i++
;
s=s+String.
valueOf(chars[count])
;
}
}
catch (UnsupportedEncodingException e) {
e.printStackTrace()
;
}
count++
;
}
return s
;
}
public static void main(String[] args){
System.
out.println(
cutString(
"我abc占",7))
;
}
} 我abc