package number;
public class TestString {
public static void main(String[] args) {
String str ="中国mobile!";
System.out.println(cutString(str,3));
}
public static String cutString(String str,int length){
StringBuffer sbStr=new StringBuffer();
int count=0,i=0;
for(;i<length&&count<length;i++,count++){
sbStr.append(str.charAt(i));
if(String.valueOf(str.charAt(i)).matches("[^\\x00-xff]")){
count++;
}
}
return sbStr.toString();
}
}
public class TestString {
public static void main(String[] args) {
String str ="中国mobile!";
System.out.println(cutString(str,3));
}
public static String cutString(String str,int length){
StringBuffer sbStr=new StringBuffer();
int count=0,i=0;
for(;i<length&&count<length;i++,count++){
sbStr.append(str.charAt(i));
if(String.valueOf(str.charAt(i)).matches("[^\\x00-xff]")){
count++;
}
}
return sbStr.toString();
}
}