我想要做這樣的事情! 因此,我只剩下字符串的網站部分。我在字符串中的報價有問題。解析字符串 - Http字符串
/////////////////////This is what i read into a string.
///<td width="118"><a href="research.html" class="navText style10 style12">
///////I wanna be able to parse this so i am only left with research.html
//I sometimes also get a string that contains:
//<a href="http://www.ucalgary.ca" class="style18"><font size="3">University of Calgary</font></a></div>
//From this string i wanna keep http://www.ucalgary.ca
到目前爲止我所得到的並不總是適用於每一種情況。我會感謝您的幫助!我的代碼是
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[] a = 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);
}
return pos;
}
}
看看Java字符串的方法。他們已經剝離和這樣 – jgr208 2014-10-08 14:51:28
目前尚不清楚,從你的輸入,「", what do you want to keep/extract ? – ToYonos 2014-10-08 14:53:44
only departmentofmedicine.com/policy.htm /// This input works but the other inputs i mentioned above dont seem to work!! For example if i use this as input///// University of Calgary – chillax786 2014-10-08 14:58:52