Using String Split
I have a pipe-delimited string in a variable named system.
I want to split it, dividing on the pipe character:
String x = system.split("|");
The above statement does not work like I wanted.
What is the argument I need to pass to the split method?
What's the string you want to split? What's the ouput? What do you expect? What does the API say about | http://java.sun.com/j2se/1.5.0/docs/...x/Pattern.html
The split( ... ) method takes a String representation of a regular expression (RE). A RE uses the pipe symbol | as a 'meta symbol', i.e. it has a special meaning for REs. You have to escape it with a backslash \| but unfortunately the backslash character is also special to javac, the Java compiler so you have to escape it twice: "\\|". Feed that String to your split( ... ) method and see for yourself.
Originally Posted by JonJacobs
>What's the string you want to split?
>>I have a pipe-delimited string in a variable named system.
>What's the ouput?
>What do you expect?
Fine :) Now do what Jos has posted in detail.
>you have to escape it twice: "\\|".
Thank you very much. That worked!