0

I have a string, "20160630048|上海11选5|2016-06-30 16:47:52|2.000|前三直选/复式", that I want to split into five strings:

MY CODE :

String splitString = Value; 
        String[] arrSplit = splitString.split("|");
        String part1 = arrSplit[0];
        String part2 = arrSplit[1];
        String part3 = arrSplit[2];
        String part4 = arrSplit[3];
        String part5 = arrSplit[4];

That means the first string will contain the characters before '|', and the second string will contain the characters after '|' and so on. Indeed i getting the value was numeric not the string. Kindly advise

Result PrintOut :

STRING SPLIT : 2 + 0 + 1 + 6 + 0
Jayden Ng
  • 141
  • 1
  • 1
  • 14

1 Answers1

2

You need to escape the pipe since it's a special character used in regular expressions: |

splitString.split("\\|");

Regex Logical Operators

XY X followed by Y
X|Y Either X or Y
(X) X, as a capturing group

Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89