java - Parsing a String - Http string -
i wanna this! left website part of string. having problems quotations within string.
/////////////////////this read string. ///<td width="118"><a href="research.html" class="navtext style10 style12"> ///////i wanna able parse left research.html //i string contains: //<a href="http://www.ucalgary.ca" class="style18"><font size="3">university of calgary</font></a></div> //from string wanna maintain http://www.ucalgary.ca what got far doesnt work every case. appreciate help!! code
public class parse { public static void main(string[] args) { string h = "<a href=\"http://www.departmentofmedicine.com/policy.htm\">"; int n = getindexof(h, '"', 0); string[] = h.substring(n).split(">"); string url = a[0].replaceall("\"", ""); //string value = a[1].replaceall("</a", ""); system.out.println(url + " " ); } public static int getindexof(string str, char c, int n) { int pos = str.indexof(c, 0); while (n-- > 0 && pos != -1) { pos = str.indexof(c, pos + 1); } homecoming pos; } }
i give pattern , matcher seek this:
string s = "<a href=\"http://www.departmentofmedicine.com/policy.htm\">"; pattern p = pattern.compile(".*href=\"([^\"]*).*"); matcher m = p.matcher(s); if(m.matches()) { system.out.println(m.group(1)); } java string parsing html-parsing
No comments:
Post a Comment