I have a string 218~2~4~6^219~1~3~3^218~5~2~2^217~10~3~8^, I want to split the string by using character with ^ . I have tried like this
String mainString = "218~2~4~6^219~1~3~3^218~5~2~2^217~10~3~8^";
String[] tokens = mainString.split("^");
for (String stri: tokens){
System.out.println("\nString tokens: " + stri);
}
But It didn’t work.. Please help me to split the string
Use
backslash(\)in front of^since its an special character(matches the beginning of the string) in regular expression. Once you addbackslash(\)in the front, its treats^as a literal, which you require to perform the split.