2

I am getting one string like below from server in response.

   "<div class=\"ExternalClass00BD08C9929B4EE8A7A9A6E9CA27A68C\"><p>\u200bTesting by Android<a href=\"/sites/Android/Shared%20Documents/1.txt\">1.txt</a><a href=\"/sites/Android/Shared%20Documents/2.txt\">2.txt</a><br></p></div>"

Now I want To get From this href value="/sites/Android/Shared%20Documents/1.txt\"

as well file name =1.txt which is enclosed in anchor tag

In short i want to split every value of HTML TAG

Is There anyway to Do this..??

If Yes then please give me suggetion how to achieve this...

Any help greatly appreciated.

2 Answers 2

3

If your response string format is consistent then you do as shown below.

String html = "<div class=\"ExternalClass00BD08C9929B4EE8A7A9A6E9CA27A68C\"><p>\u200bTesting by Android<a href=\"/sites/Android/Shared%20Documents/1.txt\">1.txt</a><a href=\"/sites/Android/Shared%20Documents/2.txt\">2.txt</a><br></p></div>";

String title = html.substring(html.indexOf("<p>") + 3, html.indexOf("<a"));
String[] splitHtml = html.split("<a");
for(int i = 0; i < splitHtml.length; i++) {

    if(splitHtml[i].contains("href=")) {
        String[] hrefSplit = splitHtml[i].split("\"");
        String url = hrefSplit[1];
        String fileName = hrefSplit[2].substring(hrefSplit[2].indexOf(">")+1,hrefSplit[2].indexOf("<")); 
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

how to get this one "\u200bTesting by Android "?? I also want this messge
@AndroidDeveloper See edits. 'title' will have "Testing by Android"
0

jQuery:

$(document).ready(function()
{
  var hrefArray;
  $('.divClass').each(function() //if you will have more than 1 link
  {
    hrefArray = $(this).DupeHref(); //getting href
    hrefArray = hrefArray.split("/").pop(); //now you have cutted array :)
  });
});

Hope i helped

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.