简体   繁体   English

如何删除锚标记并使之成为文本

[英]how to remove anchor tag and make it text

String k= <html>

<a target="_blank" href="http://www.taxmann.com/directtaxlaws/fileopencontainer.aspx?Page=CIRNO&

amp;id=1999033000019320&amp;path=/Notifications/DirectTaxLaws/HTMLFiles/S.O.193(E)30031999.htm&

amp;aa=">number S.O.I93(E), dated the 30th March, 1999
</html>

I'm getting this HTML in a String and I want to remove the anchor tag so that data is also removed from link. 我正在String获取此HTML,并且想要删除锚标记,以便也从链接中删除数据。

I just want display it as text not as a link. 我只想将其显示为文本而不是链接。

how to do this im trying to do so much not able to do please send me code regarding that im 如何做到这一点,即时通讯试图做很多无法做到的,请给我发送有关该即时通讯的代码

creating app for Android this issue im getting in android on web view. 为Android创建应用程序此问题会在网络视图中进入android。

使用JSoupjSoup.parse()

You can use the following example (don't remember where i've found it, but it works) using replace method to modify the string before showing it: 您可以使用下面的示例(不记得我在哪里找到它了,但是它可以工作)在显示它之前使用replace方法修改该字符串:

k = replace ( k, "<a target=\"_blank\" href=", "");


 String replace(String _text, String _searchStr, String _replacementStr) {
    // String buffer to store str
    StringBuffer sb = new StringBuffer();

    // Search for search
    int searchStringPos = _text.indexOf(_searchStr);
    int startPos = 0;
    int searchStringLength = _searchStr.length();
    // Iterate to add string
    while (searchStringPos != -1) {
        sb.append(_text.substring(startPos, searchStringPos)).append(_replacementStr);
        startPos = searchStringPos + searchStringLength;
        searchStringPos = _text.indexOf(_searchStr, startPos);
    }

    // Create string
    sb.append(_text.substring(startPos,_text.length()));

    return sb.toString();
} 

To substitute all the target with an empty line: 用空行替换所有目标:

    k = replace ( k, "<a target=\"_blank\" href=\"http://www.taxmann.com/directtaxlaws/fileopencontainer.aspx?Page=CIRNO&amp;id=1999033000019320&amp;path=/Notifications/DirectTaxLaws/HTMLFiles/S.O.193(E)30031999.htm&amp;aa=\">", "");

No escape is needed for slash. 斜杠不需要转义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM