我想要做这样的事情! 因此,我只剩下字符串的网站部分。我在字符串中的报价有问题。解析字符串 - 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