请教个java问题

来源:百度知道 编辑:UC知道 时间:2024/06/19 13:08:54
请教个java问题
String test=sdfj##ixlsl$$ksoxo^^
如何用split获取
str1 ##到$$之间的字符 ixlsl
str2 $$到^^之间的字符 ksoxo
非固定长处 但特征字符 ## $$ ^^ 是固定的

class test {

public static void main(String[] args) {
String str = "sdfj##ixlsl$$ksoxo^^";
System.out.println(Arrays.toString(getStrings(str)));
str = "sssss##asf$$121^^";
System.out.println(Arrays.toString(getStrings(str)));
}

public static String[] getStrings(String str) {
str = str.replace('#', ' ');
str = str.replace('$', ' ');
str = str.replace('^', ' ');
String[] strs = str.split(" ");
return strs;
}
}
哦了

如果一定要用split
System.out.println(test.split("##")[1].split("$$")[0]);
System.out.println(test.split("$$")[1].split("^^")[0]);

test.split("##|\\$\\$|\\^\\^");

ixlsl
ksoxo^^

str1 = test.split("##")[1]