您好,欢迎访问一九零五行业门户网

如何在Java中从给定的字符串中删除HTML标签?

string是java中的final类,它是不可变的,这意味着我们不能改变对象本身,但我们可以更改对象的引用。可以使用 string 类的 replaceall() 方法从给定字符串中删除 html 标签。我们可以使用正则表达式从给定字符串中删除 html 标记。从字符串中删除 html 标签后,它将返回一个字符串作为普通文本。
语法public string replaceall(string regex, string replacement)
示例public class removehtmltagstest { public static void main(string[] args) { string str = "<p><b>welcome to tutorials point</b></p>"; system.out.println("before removing html tags: " + str); str = str.replaceall("\<.*?\>", ""); system.out.println("after removing html tags: " + str); }}
输出before removing html tags: <p><b>welcome to tutorials point</b></p>after removing html tags: welcome to tutorials point
以上就是如何在java中从给定的字符串中删除html标签?的详细内容。
其它类似信息

推荐信息