To remove HTML tags from Java, you must first remove the regular double quotation marks

Time:2021-9-24

Copy codeThe code is as follows:
public static String htmlToStr(String htmlStr){
String result = “”;
boolean flag = true;
if(htmlStr==null){
return null;
}

Htmlstr = htmlstr.replace (“\” “,”); / / remove quotation marks

char[] a = htmlStr.toCharArray();
int length=a.length;
for(int i=0;i<length;i++){
if(a[i]=='<‘){
flag=false;
continue;
}
if(a[i]==’>’){
flag=true;
continue;
}
if(flag==true){
result+=a[i];
}
}
return result.toString();
}