我想在我的应用程序中的某处显示网站的一些内容。以下是它将获得的输入的示例:
<tr class='list even'><td class="list inline_header" colspan="6" >09e Klasse 9e (Kla)</td></tr>
Run Code Online (Sandbox Code Playgroud)
它应该输出类似以下内容:
09e Klasse 9e (Kla)
Run Code Online (Sandbox Code Playgroud)
我努力了
text.replaceAll("<*>", "");
Run Code Online (Sandbox Code Playgroud)
但它并没有按照我想要的方式工作。
我正在寻找这个问题的答案,但针对的是 Java/Android。
大家好,我有一个java字符串,我想删除除新行标签之外的所有html标签<br>,</br>并将文本保留在标签内(如果有文本)。2-解析文本结果后相互连接,如: text1andtext2 ,文本之间没有空格分隔,我也想这样做。
这就是我正在做的:
String html = "<div dir=\"ltr\">hello my friend<span>ECHO</span><br>how are you ?<br><br><div class=\"gmail_quote\">On Mon, Feb 14, 2011 at 10:45 AM, My Friend <span dir=\"ltr\"><<a href=\"mailto:notifications@mydomain.com\">notifications@mydomain.com</a>></span> wrote:<br> "
+ "<blockquote class=\"gmail_quote\" style=\"margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;\"> ";
String parsedText = html.replaceAll("\\<.*?\\>", "");
System.out.println(parsedText);
Run Code Online (Sandbox Code Playgroud)
电流输出:
hello my friendECHOhow are you ?On Mon, Feb 14, 2011 at 10:45 AM, My Friend <notifications@mydomain.com> wrote:
Run Code Online (Sandbox Code Playgroud)
期望的输出:
hello my friend ECHO <br> …Run Code Online (Sandbox Code Playgroud) 我在我的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) 我有一个字符串,我想用<和>删除所有标签
例如:
在字符串中
<title>Java Code</title>
Run Code Online (Sandbox Code Playgroud)
将会
Java Code
Run Code Online (Sandbox Code Playgroud)
和
<pre><font size="7"><strong>Some text here
</strong></font><strong>
Run Code Online (Sandbox Code Playgroud)
将会
Some text here
Run Code Online (Sandbox Code Playgroud)
如何使用charAt(i)?提前致谢
我在用
URL url = new URL("http://www.puzzlers.org/pub/wordlists/pocket.txt");
Scanner s = new Scanner(url.openStream());
Run Code Online (Sandbox Code Playgroud)
阅读我的文档。但是当我尝试输出字符串时,我得到了一些不必要的标签。我的要求是能够按原样阅读文档(即没有任何不必要的标签。)
下面是我写的一段代码:
URL url = new URL("Link");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
String[] wordArray;
int wordCount;
while ((str = in.readLine()) != null) {
System.out.println(str);
wordArray = str.split("\\s+");
wordCount = wordArray.length;
System.out.println("Word count is = " + wordCount);
}
in.close();
Run Code Online (Sandbox Code Playgroud)
以下是我得到的输出。我不想要任何不必要的标签,您可以在下面的输出中看到。我只想要您可以在标签之间看到的实际文本。不必要的标签意味着
等等,您可以在下面的输出片段中看到。我只想在字符串中包含“美国证券和交易所”等文本。
Word count is = 1
<P STYLE="font: 10pt/normal Arial, Helvetica, Sans-Serif; margin: 0; padding: 0; text-align: center"></P>
Word count is = 12
Word count is …Run Code Online (Sandbox Code Playgroud)