0

I am reading an XML file obtained from a web service. I have an LinkedList<String> variable in which it contains a string. In that string there are certain words which I need to split. An example of a string contained in one of the elements in the LinkedList is like this: "happy|elated|good"

I basically need get the string by splitting it where it meets the | symbol. I tried splitting it by using .split("|"); but that splitted it to single characters and not words. I then tried [^|] and that did nothing.

Im writing this in java.

EDIT = Nevermind,found out the problem. Forgot the \ in the regex

  • 3
    try `.split("\\|")` - the split method takes a regular expression and "|" is a special character in regular expressions, so you need to escape it. – Florian Schaetz Mar 19 '16 at 19:35
  • "Doesn't work" is not good enough. Best is to post a minimal, working piece of code that repros' the problem. You also should tell us how your input data looks like, what you expect should happen; and what actually happens. Besides: did you do any prior research? This site is **full** with questions/answers around splitting strings in java. And finally: did you carefully read the javadoc around String.split()? Most often, that alone helps you figuring what is going on ... – GhostCat Mar 19 '16 at 19:35
  • @FlorianSchaetz I just found out after reading the docs. Anyways, thanks for the input. – Tarikh Chouhan Mar 19 '16 at 19:37

0 Answers0