有没有一种从Java字符串中删除HTML的好方法?一个简单的正则表达式
replaceAll("\\<.*?>","")
Run Code Online (Sandbox Code Playgroud)
会工作,但&不会正确转换,两个尖括号之间的非HTML将被删除(即.*?正则表达式将消失).
我Html.fromHtml用来查看html TextView.
Spanned result = Html.fromHtml(mNews.getTitle());
...
...
mNewsTitle.setText(result);
Run Code Online (Sandbox Code Playgroud)
但Html.fromHtml现在已经在Android N +中弃用了
我/我如何找到新的方法?
我有以下代码:
public class NewClass {
public String noTags(String str){
return Jsoup.parse(str).text();
}
public static void main(String args[]) {
String strings="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN \">" +
"<HTML> <HEAD> <TITLE></TITLE> <style>body{ font-size: 12px;font-family: verdana, arial, helvetica, sans-serif;}</style> </HEAD> <BODY><p><b>hello world</b></p><p><br><b>yo</b> <a href=\"http://google.com\">googlez</a></p></BODY> </HTML> ";
NewClass text = new NewClass();
System.out.println((text.noTags(strings)));
}
Run Code Online (Sandbox Code Playgroud)
我有结果:
hello world yo googlez
Run Code Online (Sandbox Code Playgroud)
但我想打破界限:
hello world
yo googlez
Run Code Online (Sandbox Code Playgroud)
我查看了jsoup的TextNode#getWholeText()但我无法弄清楚如何使用它.
如果<br>我解析了标记中的a ,那么如何在结果输出中获得换行符?
我越来越[OBJ]显示在屏幕上,当我尝试设置ImageSpan上的文本View..it显示/ uFFFC Unicode字符,而不是屏幕上的图像,即与OBJ虚线框里面写的.
我有一个这样的字符串:John \n Barber现在我想用实际的新行字符替换\n,这样它就会变成
John
理发师
这是我的代码
replaceAll("\\n", "\n");
Run Code Online (Sandbox Code Playgroud)
但它不起作用,并给我相同的字符串 John \n Barber
我正在android中创建一个示例项目.我正在使用示例rss feed.
在这样的xml描述中,
<![CDATA[
<p>15 Mar 2012</p>
<a href="http://newsonair.nic.in/full_news.asp?TOP2">
<p style='FONT-SIZE: 12px; LINE-HEIGHT: 150%' align='justify'>
<img style='FLOAT: left; MARGIN-RIGHT: 5px' height='100' width='100' src=http://www.newsonair.nic.in/writereaddata/news_pictures/PICNEWS1.jpg?
0.7055475></a><br/>
Parliament was today disrupted over the issue of removal of Trinamool Congress's leader and the Railway Minister, Mr.Dinesh Trivedi from the Council of Ministers.</p><br clear="all" />
]]>
Run Code Online (Sandbox Code Playgroud)
我想要这样显示,
Parliament was today disrupted over the issue of removal of Trinamool Congress's leader and the Railway Minister, Mr.Dinesh Trivedi from the Council of Ministers.
Run Code Online (Sandbox Code Playgroud)
任何人都可以说出这个想法.谢谢.
我是Android技术的新手.我必须阅读其中有HTML标签的XML文件,例如<b>所以我必须在我在屏幕上显示这些标签之前将其删除.如果你知道在显示之前删除这些的任何方法,请帮助我.
我在我的android应用程序中使用json,实际上在列表视图中我的文本中也显示了html标签,我怎样才能显示避免html标签的文本
Mainactivity.java
public class MainActivity extends ListActivity implements FetchDataListener
{
private ProgressDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_list_item);
initView();
}
private void initView()
{
// show progress dialog
dialog = ProgressDialog.show(this, "", "Loading...");
String url = "http://floating-wildwood-1154.herokuapp.com/posts.json";
FetchDataTask task = new FetchDataTask(this);
task.execute(url);
}
@Override
public void onFetchComplete(List<Application> data)
{
// dismiss the progress dialog
if ( dialog != null )
dialog.dismiss();
// create new adapter
ApplicationAdapter adapter = new ApplicationAdapter(this, data);
// set the adapter to …Run Code Online (Sandbox Code Playgroud) 我有一个ieString中有评论。我想删除所有这些。<! --><!comment1-->
RE 是什么?
我试过:
replaceAll("\\<!.*?\\-\\-\\>", "");
Run Code Online (Sandbox Code Playgroud)
但这没有用。我尝试循环和替换并且它有效,但我正在寻找正则表达式
我已经尝试过该墨水中提到的 html.fromHtml,但它不起作用。为此我在这里提出了另一个问题
例如下面的字符串
<style> <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} @font-face {font-family:Tahoma; panose-1:2 11 6 4 3 5 4 4 2 4;} @font-face {font-family:Webdings; panose-1:5 3 1 2 1 5 9 6 7 3;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in; margin-bottom:.0001pt; …Run Code Online (Sandbox Code Playgroud)