Reputation: 899
I have a file containing lines of this type:
"Andorra la Vella|ad|Andorra la Vella|20430|42.51|1.51"
I basically just want to have a String Array containing the entries between the | delimiter:
["Andorra la Vella", "ad", "Andorra la Vella", "20430", "42.51", "1.51"]
Can this be done with regular expressions?
Upvotes: 16
Views: 67713
Reputation: 221
An alternative is to use String.split(...)
String s="Hi farshad zeinali/ how are you?/i have a question!/can you help me?";
String[] ss=s.split("/");
for(int i=0;i<ss.length;i++)
{
System.out.println(ss[i]);
}
Upvotes: 22
Reputation: 80176
Yes use String.split() for each line as you read it from the file.
line.split("\\|");
Upvotes: 29