Java split string “^ ^” [copy]
•
Java
See the English answer > java split on ^ (CARET?) not working,is this a special character? 6
***^|^100^|^101^|^102^|^103^|^104^|^
I want to split it with "^ ^", and the result will be:
*** 100 101 102 103 104
The following is my sample code, but it didn't get the expected results. Did I misunderstand the split mode?
String a = "***^|^100^|^101^|^102^|^103^|^104^|^105^|^106^|^107^|^108^|^"; String [] split ; split = a.split("^|^"); for(int i=0; i<split.length; i++) { System.out.println(split[i]); }
resolvent
Solution
^And | are special chaters you need to escape
split = a.split("\\^\\|\\^");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码