1

In my jsoup class, i retrive the text of each tag as follows

  doc = Jsoup.parse(getxml,"", Parser.xmlParser());
    libelle = doc.select("belle");

resulting in pin pin pin apple apple apple 34233 4433 314434

then i split it as

  libel = libelleCompte.text().toString().split(" ");

the original tag is as follows

<pretty>
<belle> pin pin pin</belle>
<belle>apple apple apple</belle>
<belle>34233</belle>
<belle>4433</belle>
<belle>314434</belle>
</pretty>

the result should be

pin pin pin apple apple apple 34233 4433 314434

any idea of how to split it after each tag ?

Ali
  • 2,012
  • 3
  • 25
  • 41
yakusha
  • 817
  • 7
  • 13
  • 21

2 Answers2

1

Edited:

You can't do it with simple regex, although the following code can help you:

    String testStr = "pin pin pin apple apple apple 34233 4433 314434";
    String[] splitedText = testStr.split("\\s+");
    ArrayList<String> tmpArray = new ArrayList<String>();
    int strCounter = 2;
    String tmpStr = "";

    for (int i = 0; i < splitedText.length; i++)
    {
        tmpStr += splitedText[i] + " ";
        if (strCounter == i)
        {
            tmpArray.add(tmpStr);
            tmpStr = "";
            strCounter += 3;
        }
    }

    // Test for result
    for (int i = 0; i < tmpArray.size(); i++)
        Log.w("Counter", i + " => " + tmpArray.get(i));

Result:

0 => pin pin pin

1 => apple apple apple

2 => 34233 4433 314434

Note: The \\s is equivalent to [\\t\\n\\x0B\\f\\r].

Ali
  • 2,012
  • 3
  • 25
  • 41
  • nope i want index 0 1 2 to be on the same line index 3 4 5 on second line and the remaining on a respective index that is each tag should have a unique index – yakusha Apr 05 '13 at 04:27
  • ok but the content is dynamic, there can be 3 or more words in a sentence. so . dont worry thanks i'll mark you as the right answer though my problem is not solved. – yakusha Apr 05 '13 at 11:28
1
String str = "Hello How are you";
String arrayString[] = str.split("\\s+") 

See below link:-

How to split string in Java on whitespace?

Community
  • 1
  • 1
duggu
  • 37,851
  • 12
  • 116
  • 113