首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

html超链接怎么转化为字符串的有关问题

2012-01-05 
html超链接如何转化为字符串的问题假设现在我想分析一个锚标签a hrefhttp://tech.sina.com.cn/n/2008-0

html超链接如何转化为字符串的问题
假设现在我想分析一个锚标签<a href="http://tech.sina.com.cn/n/2008-05-22/08132210131.shtml" target="_blank">低预算购本攻略</a> 
但当我尝试将其转化为字符串时会出现错误Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ ),我已经用\恢复它字面意思的啊,我的字符串如下:String str = "<a href=\"http:\/\/tech\.sina\.com.cn\/n\/2008-05-22\/08132210131\.shtml\" target=\"_blank\">低预算购本攻略<\/a>";

[解决办法]
String s = "<a href=\"http://tech.sina.com.cn/n/2008-05-22/08132210131.shtml\" target=\"_blank\">";
[解决办法]
String str = "<a href='http://tech.sina.com.cn/n/2008-05-22/08132210131.shtml' target='_blank'>";
[解决办法]
你可能需要这段代码

Java code
private String htmlFilter( String line ) {        if( line == null || line.equals("") ) {            return "";        }        // replace ampersands with HTML escape sequence for ampersand;        line = replace(line, "&", "&#38;");        // replace \" sequences with HTML escape sequences;        line = replace(line, "\\\"", "&#92;&#34");        // replace the \\ with HTML escape sequences. fixes a problem when        // backslashes preceed quotes.        line = replace(line, "\\\\", "&#92;&#92;" );        // replace less-than signs which might be confused        // by HTML as tag angle-brackets;        line = replace(line, "<", "&#60;");        // replace greater-than signs which might be confused        // by HTML as tag angle-brackets;        line = replace(line, ">", "&#62;");        return multiLineCommentFilter(line);    }
[解决办法]
./在正则表达式中要转义,但在java字符串中是不需要转义的
String str = "\\\"\\.\\/";
写正则表达式要这样才行

热点排行