Moe
Moe

Reputation: 1557

Android from string to string array

hi to all i have this code have this code which reads a some text and it extracts any strings between the '[' and ']' and it should print it on the screen

String lines[] = {addressString};
for (int i = 0; i < lines.length; i++) {
    int be = lines[i].indexOf('[');
    int e = lines[i].indexOf(']');
    String fields = lines[i].substring(be+1, e);
}

my question is that i want to change the string "fields" to an array string so when i print it i can print it as fields[0],fields[1],....etc until the end of the text....?

any suggestions...??

Thanks a lot

Upvotes: 0

Views: 1830

Answers (1)

Robert Massaioli
Robert Massaioli

Reputation: 13477

Is this what you mean?

String lines[] = {addressString};
String fields[] = new String[lines.length];
for (int i = 0; i < lines.length; i++) {
    int be = lines[i].indexOf('[');
    int e = lines[i].indexOf(']');
    fields[i] = lines[i].substring(be+1, e);
}

Upvotes: 1

Related Questions