package sorttest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* 根据输入的字符串进行要求截取,
* 如遇到中文不满两个字节的便舍弃中文,如果满足两个字节则获取过来
*/
public class Splitstr {
public static String splstr(String mt, int v) {
String str=mt;
int num = v;
String stt = "";
for (int i = 0; i < str.length(); i++) {
if (i < num - 2) {
String substr = str.substring(i ,i+1);
System.out.println("i="+i);
if (substr.matches("[/u4e00-/u9fa5]")&&(i + 1) < (num - 1)) {
stt += substr;
} else {
String ch = new Character(str.charAt(i)).toString();
stt += ch;
}
}
System.out.println();
System.out.println(stt);
}
return stt;
}
public static void main(String[] args) throws IOException {
System.out.println("please input string and splitnum:");
while(true){
BufferedReader br=new BufferedReader(new InputStreamReader(System.in ));
BufferedReader num=new BufferedReader(new InputStreamReader(System.in ));
String b=br.readLine();
int inu=Integer.parseInt(num.readLine());
String maxstr=splstr(b,inu);
System.out.println("最大子串为:" + maxstr);
if(br.readLine().equals("exit") && num.equals(null)){
System.exit(1);
}
}
}
}