gaussd
gaussd

Reputation: 899

Parse String with delimiter symbol into Array

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

Answers (2)

user1794850
user1794850

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

Aravind Yarram
Aravind Yarram

Reputation: 80176

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

line.split("\\|");

Upvotes: 29

Related Questions