比如這樣一個字符串
String a = "你好,今天是@2015@年@7@月@15@日";
String b = "時間為@16@@:@@05@";
怎麼樣截取2個一對的@中間的字符串 a = 2015,7,15 b = 16,:,05
public static String getResult(String str,String splitStr){
String[] arr = ("1"+str+"1").split(splitStr);
StringBuilder sd = new StringBuilder();
for(int i=1;i<arr.length-1;i++){
sd.append(arr[i]);
}
return sd.toString();
}
public static void main(String[] args) {
String a = "你好,今天是@2015@年@7@月@15@日";
String b = "時間為@16@@:@@05@";
a = getResult(a,"@");
b = getResult(b,"@");
System.out.println("a="+a);
System.out.println("b="+b);
}