将html string / tag替换为另一个html字符串/标记android

时间:2011-10-14 06:46:03

标签: android

我想将html标签替换为另一个标签:

for (int i = 1; i <= htmlarray.size(); i++) 
{
    Content = Content.replaceAll("<Sup><FONT size=\"+1\">" + i+ "<","<Sup><FONT size=\"+2\"><a style=\"color: #664b38\"href=\"http:/"+ i + "\">" + i + "</a><");
}

1 个答案:

答案 0 :(得分:1)

我得到了答案,现在是:

public String replace(CharSequence target, CharSequence replacement) {
return Pattern.compile(target.toString(), Pattern.LITERAL).matcher(target).replaceAll(Matcher.quoteReplacement(replacement.toString()));
}

这个功能对我有用。并且还使用replace()函数。

for (int i = 1; i <= htmlarray.size(); i++) 
{
 Content = Content.replace("<Sup><FONT size=\"+1\">" + i+ "<","<Sup><FONT size=\"+2\"><a style=\"color: #664b38\"href=\"http:/"+ i + "\">" + i + "</a><");
}