For some reason this parsing technique doesn't work when I use "|"
to parse the string.
My java code looks like this
public class Testing{
public static void main(String[] args){
String sentence = "SA|2|What is the capital of Italy|Rome";
System.out.println(sentence);
System.out.println("---------------------------");
String[] tokens = sentence.split("|");
for(String word: tokens)
System.out.println(word);
}
}
So my output looks like this for some reason
SA|2|What is the capital of Italy|Rome
---------------------------
S
A
|
2
|
W
h
a
t
i
s
t
h
e
c
a
p
i
t
a
l
...(and so on)
What I want it to do is to display the entire string like this instead of what it is giving me like this
SA|2|What is the capital of Italy|Rome
---------------------------
SA
2
What is the capital of Italy
Rome
Does anybody know why it is causing every letter to be printed per line and doesn't print it with every word?