Reputation: 2127
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.
Upvotes: 2
Views: 2074
Reputation: 3455
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("<"));
}
}
Upvotes: 3
Reputation: 390
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
Upvotes: 0