I have a string using the pipe symbol “| as the delimiter. However, the string data also contains the pipe symbol. Is there a way to ignore this?
Example:
name|address|age
John|123 Wood Road|Street, London|25
Therefore when I do this –
text.split("\\|")
gives me:
John
123 Wood Road
Street, London
25
I am expecting this:
John
123 Wood Road|Street, London
25
String.split()can’t differentiate between different occurrences of the same symbol. You’ll have to put in place some rules, either in code or in a regex. Based on your data, I’m guessing that while you say that pipe can occur within the string data, it really can’t occur in name or age, so you could do something like this: