我有一个巨大的字符串,它是通过JSOUP.I取得的字符串完整的html。使用String Bufer替换API(替换(int startIndex,int endIndex, “要改变字符串)。该字符串缓冲区填充perfectly.But当我尝试更换新的字符串缓冲区的HTML的子这是行不通的。用一个StringBuffer子字符串替换一个子字符串
这里是代码片段。
html = html.replace(divStyle1.trim(), heightwidthM.toString().trim());
最初的大html是
<!DOCTYPE html>
<html xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="SAF" id="global-header-light">
<head>
</head>
<body>
**<div style="background-image: url(http://aka-cdn-ns.adtech.de/rm/ads/23274/HPWomenLOFT_1381687318.jpg);background-repeat: no-repeat;-webkit-background-size: 1001px 2059px; height: 2059px; width: 1001px; text-align: center; margin: 0 auto;">**
<div style="height:2058px; padding-left:0px; padding-top:36px;">
<iframe style="height:90px; width:728px;"/>
</div>
</div>
</body>
</html>
的divStyle1字符串是
background-image: url(http://aka-cdn-ns.adtech.de/rm/ads/23274/HPWomenLOFT_1381687318.jpg);background-repeat: no-repeat;-webkit-background-size: 1001px 2059px; height: 2059px; width: 1001px; text-align: center; margin: 0 auto;
和字符串缓冲器具有值
背景图像:网址(http://aka-cdn-ns.adtech.de/rm/ads/23274/HPWomenLOFT_1381687318.jpg);background-repeat:不重复; -webkit-背景尺寸:1001PX 2059px;高度:720像素;宽度:900px; text-align:center;保证金:0汽车;
不起作用,其中divStyle是最后一个HTML的字符串(在String中),heightwidthM是必须替换的Stringbuffer值。它不会抛出任何错误,但它也不会改变它。
感谢 斯瓦拉杰
这是什么值?如果'html'很大,只需发布字符串的相关部分。你确定有完全匹配吗? – rgettman
考虑到您使用的是jsoup,并且jsoup让您的生活更轻松地处理html文档,为什么不从您的html创建'org.jsoup.nodes.Document',找到您需要的标签并对其进行修改? –
@rgettman进行了必要的编辑 –