I have a string that\'s like this: 1|\"value\"|;
I want to split that string and have chosen | as the separator.
My code looks like
It won't work this way, because you have to escape the Pipe | first. The following sample code, found at (http://www.rgagnon.com/javadetails/java-0438.html) shows an example.
public class StringSplit {
public static void main(String args[]) throws Exception{
String testString = "Real|How|To";
// bad
System.out.println(java.util.Arrays.toString(
testString.split("|")
));
// output : [, R, e, a, l, |, H, o, w, |, T, o]
// good
System.out.println(java.util.Arrays.toString(
testString.split("\\|")
));
// output : [Real, How, To]
}
}