I have a String in java that looks something like this -
我在java中有一个看起来像这样的字符串 -
“id\uFF1Aabc123, ip\uFF1A127:0:0:1”
How do I split this in java based on the \uFF1A? So far I have tried this -
如何基于\ uFF1A在java中拆分它?到目前为止,我试过这个 -
Pattern p = Pattern.compile("\uFF1A", Pattern.UNICODE_CHARACTER_CLASS);
System.out.println(p.split(s)[0]);
And it just returns back the entire string.
它只返回整个字符串。
1 个解决方案
#1
3
Your code works.
你的代码有效。
However, you can just use the String.split
method:
但是,您可以使用String.split方法:
String s = "id\uFF1Aabc123, ip\uFF1A127:0:0:1";
String[] splitted = s.split("\uFF1A");
System.out.println(splitted[0]);
System.out.println(splitted[1]);
System.out.println(splitted[2]);
#1
3
Your code works.
你的代码有效。
However, you can just use the String.split
method:
但是,您可以使用String.split方法:
String s = "id\uFF1Aabc123, ip\uFF1A127:0:0:1";
String[] splitted = s.split("\uFF1A");
System.out.println(splitted[0]);
System.out.println(splitted[1]);
System.out.println(splitted[2]);