Parse String with delimiter symbol into Array

gaussd picture gaussd · Nov 2, 2012 · Viewed 63.3k times · Source

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?

Answer

Aravind Yarram picture Aravind Yarram · Nov 2, 2012

Yes use String.split() for each line as you read it from the file.

line.split("\\|");