我无法从此字符串中拆分值:
"Food 1 | Service 3 | Atmosphere 3 | Value for money 1 "
这是我目前的代码:
String rat_values = "Food 1 | Service 3 | Atmosphere 3 | Value for money 1 ";
String[] value_split = rat_values.split("|");
Run Code Online (Sandbox Code Playgroud)
[,F,o,o,d ,, 1 ,, | ,,, S,e,r,v,i,c,e,,3,... ,, A,t,m,o,s,p, h,e,r,e,,3,| ,, V,a,l,u,e,f,o,r ,, m,o,n,e,y ,, 1,]
食物1
服务3
气氛3
物有所值1
Java官方文档指出:
"boo:and:foo"例如,字符串使用这些表达式生成以下结果Regex结果:
{ "boo", "and", "foo" }"
Run Code Online (Sandbox Code Playgroud)
这就是我需要它工作的方式.但是,如果我运行这个:
public static void main(String[] args){
String test = "A|B|C||D";
String[] result = test.split("|");
for(String s : result){
System.out.println(">"+s+"<");
}
}
Run Code Online (Sandbox Code Playgroud)
它打印:
><
>A<
>|<
>B<
>|<
>C<
>|<
>|<
>D<
Run Code Online (Sandbox Code Playgroud)
这远非我所期望的:
>A<
>B<
>C<
><
>D<
Run Code Online (Sandbox Code Playgroud)
为什么会这样?