这是我的Html:
desc=desc=<a target="_blank" href="http://www.taxmann.com/corporatelaws/fileopencontainer.aspx?Page=CIRNO&id=27000000000000002519&search=">A. P. (DIR Series) Circular No. 46 dated June 14, 2005</a>
这里id =值变化和corporatelaws或directtaxlaws
String k = replace ( desc, "<a target=\"_blank\" href=\"http://www.taxmann.com/corporatelaws/fileopencontainer.aspx?Page=RULES&id=35000000000000001648&search=\">", "");
在desc中我得到HTML我有替换命令我必须删除链接所以我从锚标记中选择数据目标是动态的,其中id变化我能够替换链接到目标为
的文本但是当目标发生变化时,我的意思是说如果id发生变化,它就不会将链接替换为文本。
请告诉我如何获取和设置id值,这样如果目标是动态的,我们可以将链接替换为文本。我是android编程的新手。
String str = "http://www.taxmann.com/corporatelaws/fileopencontainer.aspx?Page=CIRNO&id=27000000000000002519&search=";
int indexoff = str.indexOf("id=");
int indexofl = str.indexOf("&search=");
String strsub = str.substring(indexoff + 3, indexofl - indexoff - 3);
String strstaticstring = "http://www.taxmann.com/corporatelaws/fileopencontainer.aspx?Page=CIRNO&id=" + strsub + "&search=";
String k = desc.replace(strstaticstring, "");
我试过这个,但我不知道如何选择corporte或者directtaxlaws会来......
答案 0 :(得分:0)
尝试这种方式:
String str ="";
if(desc.contains("http://www.taxmann.com/corporatelaws/")==true)
{
str = "http://www.taxmann.com/corporatelaws/fileopencontainer.aspx?Page=CIRNO&id=27000000000000002519&search=";
}
if(desc.contains("http://www.taxmann.com/directtaxlaws/")==true)
{
str = "http://www.taxmann.com/directtaxlaws/fileopencontainer.aspx?Page=CIRNO&id=27000000000000002519&search=";
}
if(desc.contains("http://www.taxmann.com/corporte/")==true)
{
str = "http://www.taxmann.com/corporte/fileopencontainer.aspx?Page=CIRNO&id=27000000000000002519&search=";
}
或者你可以在“/”的基础上拆分你的字符串并检查字符corporte,directtaxlaws等。
String str = "http://www.taxmann.com/corporatelaws/fileopencontainer.aspx?Page=CIRNO&id=27000000000000002519&search=";
string[] strarr = str.Split('/');
在strarr [3]中你将获得corporatelaws值sa字符串用于收缩整个字符串以替换desc