This question already has answers here:
Why does String.split need pipe delimiter to be escaped?
(3个答案)
5年前关闭。
我有一个字符串completeString
我正在尝试使用分割此字符串
当我得到第一个要素时
我正在获取空字符串。对于接下来的两个元素,我只会得到第一个字母,即C和O(比较)。
(3个答案)
5年前关闭。
我有一个字符串completeString
String completeString = "Comp 30440 Software Engineering Project|20-credit module|Is part of your(Conversion) Programme.Deals with the creation of a twitter sentiment analysis application";
我正在尝试使用分割此字符串
String[] array = completeString.split("|");
当我得到第一个要素时
String first = array[0];
我正在获取空字符串。对于接下来的两个元素,我只会得到第一个字母,即C和O(比较)。
最佳答案
|
需要转义,所以\\|
应该可以解决问题
10-05 22:50