有一字符串String str=” <font color=\"#99CCFF\">你好,欢迎你</font>”;

来源:百度知道 编辑:UC知道 时间:2024/06/18 09:33:30
请写一方法把“你好,欢迎你”打印出来,字符串不要显示出来!
大哥大姐帮忙啊,有加分,在线等,用JAVA写啊

public class Class1 {

static String str="<font color=\"#99CCFF\">你好,欢迎你</font>";
static String getChs() {
int idx1 = str.indexOf(">");
if (idx1 >= 0) {
if ((idx1 + 1) >= str.length()) {
return "";
}

String s = str.substring(idx1 + 1);
int idx2 = s.indexOf("<");
if (idx2 >=0 ) {
return s.substring(0,idx2);
}

}

return "";
}
public static void main(String[] args) {

System.out.println(getChs());
}
}

String s = str.substring(str.indexOf(">") + 1);
System.out.println(s.substring(s, s.indexOf("<"));

你这是web开发吧??如果是在jsp页面中,你直接就用
out.println(str);输出就可以。输出后就只有 你好,欢迎你 这几个字。别的都是html元素,不会显示的。