从Dart中的字符串中删除HTML标签 [英] Remove HTML tags from a String in Dart

查看:622
本文介绍了从Dart中的字符串中删除HTML标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我一直在努力实现这一目标,我有一个字符串,其中包含许多HTML标记,这些标记采用某种编码形式
Like& lt;和& gt; (无空格)在字符串之间。
谁能协助我删除这些标签,以便获得清晰的字符串?

I’ve been trying to achieve this for a while, I have a string which contains a lot of HTML tags in it which is in some encoded form Like & lt; and & gt; (without the spaces) in between the string. Can anyone assist me in removing those tags so that I can get a plain string?

推荐答案

最后,我使用html包实现了这一点

Finally I achieved this using the html package

这是我的操作方式

import 'package:html/parser.dart';


//here goes the function 
String _parseHtmlString(String htmlString) {
final document = parse(htmlString);
final String parsedString = parse(document.body.text).documentElement.text;

return parsedString;
}

我不知道是否有更清洁的方法可以这样做,但这对我有用

I don’t know if there is any cleaner way to do this but this one worked for me.

这篇关于从Dart中的字符串中删除HTML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆