日期:2014-05-17 浏览次数:20917 次
String str = "100<n<1000";
或 str = "100≤n≤1000";
或 str = "100≤n<1000";
或 str = "100<n≤1000";
public static void main(String[] arg) {
String intputStr = "100≤n<1000";
String arr[] = intputStr.split("[<≤]");
String regexArr[] = intputStr.split("n");
StringBuilder sbBuilder = new StringBuilder();
List<String> regexList = new ArrayList<String>();
for (String s : regexArr) {
if (s.contains("<")) {
regexList.add("<");
} else if (s.contains("≤")) {
regexList.add("≤");
}
}
int listIndex = 0;
for (int i = 0; i < arr.length; i++) {
sbBuilder.append(arr[i]).append(",");
if (regexList.size() - 1 >= listIndex) {
sbBuilder.append(regexList.get(listIndex)).append(",");
}
listIndex++;
}
System.out.println(sbBuilder.toString().substring(0,
sbBuilder.toString().length() - 1));
}