0

I have following text:

    <option value="{0}">hello1</option>
    <option value="{1}">hello2</option>
    <option value="{2}">hello3</option>
    <option value="{3}">hello4</option>
    <option value="{4}">hello5</option>
    <option value="{5}">hello6</option>
    <option value="{6}">hello7</option>
    <option value="{7}">hello8</option>

All above is in one String.

I have 2 Arrays:

valueArray;
nameArray;

So, any tip on how to get the helloX into nameArray and get all value into valueArray?

//Simon

AndroidXTr3meN
  • 399
  • 2
  • 9
  • 19

2 Answers2

1

You can find the position of > using start =str.indexof(">");

also position of </ using stop=str.indexof("</");

then get string str = str.subString(start,stop);

you will get helloX...

=====================================

https://stackoverflow.com/a/10000095/1289716 see this answer.....

replace your { bracket and } bracket with & #123; ** and **& #125;

Community
  • 1
  • 1
MAC
  • 15,799
  • 8
  • 54
  • 95
  • I find this type of solution to be clunky and error prone. It will quickly fail with ``. – Nate Apr 26 '12 at 17:59
0

Use a regex and populate the arrays. Here is a small test program I wrote:

public static void main(String [] args) {
    Pattern p = Pattern.compile("<option value=\"(.*?)\">(.*?)</option>");
    String line = "<option value=\"{1}\">hello0</option>";
    Matcher m = p.matcher(line);
    while (m.find()) {
        String value = m.group(1);
        String name = m.group(2);
        System.out.println(value);
        System.out.println(name);
        // Now add to your arrays
    }
}

I would not use this as a standard method for parsing a complicated xml file. Use an xml parser if this is the case.

Nate
  • 557
  • 3
  • 8