我是
Android开发的菜鸟,我试图从字符串中删除一串动态字符.我的字符串:
"Beginning of String....<img src="http://webaddress.com" height="1" width="1"/>"
我想删除“& lt”,“& gt”以及它们之间的所有内容.我想要的只是“字符串的开头……”到目前为止,我已经尝试过这个并没有成功.
description = description.replaceFirst("(?s)(<)(.*?)(>)","$1$3");
此外,我尝试了类似的类似字符串,它工作正常,所以我不明白我做错了什么.
description = description.replaceFirst("(?s)()(.*?)()","$1$3");
我的课
public class RssReader {
private final static String BOLD_OPEN = "";
private final static String BOLD_CLOSE = "";
private final static String BREAK = "
";
private final static String ITALIC_OPEN = "";
private final static String ITALIC_CLOSE = "";
private final static String SMALL_OPEN = "";
private final static String SMALL_CLOSE = "";
public static List getLatestRssFeed(){
String feed = "http://feeds.feedburner.com/MetalMarketCommentary";
//http://globoesporte.globo.com/dynamo/futebol/times/vasco/rss2.xml
//http://feeds.feedburner.com/GoldMoneyGoldResearch +
//http://feeds.feedburner.com/GoldsilvercomNews +
//http://feed43.com/7466558277232702.xml
//http://feeds.feedburner.com/SilverGoldDaily
//http://feeds.feedburner.com/MetalMarketCommentary
//http://link.brightcove.com/services/player/bcpid1683318714001?bckey=AQ~~,AAAAC59qSJk~,vyxcsD3OtBPHZ2UIrFX2-wdCLTYNyMNn&bclid=1644543007001&bctid=1854182861001
RSSHandler rh = new RSSHandler();
List articles = rh.getLatestArticles(feed);
Log.e("RSS ERROR", "Number of articles " + articles.size());
return fillData(articles);
}
private static List fillData(List articles) {
List items = new ArrayList();
for (Article article : articles) {
JSONObject current = new JSONObject();
try {
buildJsonObject(article, current);
} catch (JSONException e) {
Log.e("RSS ERROR", "Error creating JSON Object from RSS feed");
}
items.add(current);
}
return items;
}
private static void buildJsonObject(Article article, JSONObject current) throws JSONException {
String title = article.getTitle();
String description = article.getDescription();
description = description.replaceFirst("(?s)()(.*?)()","$1$3");
int start = description.indexOf(".&");
description= description.substring(0, start);
String date = article.getPubDate();
String imgLink = article.getImgLink();
StringBuffer sb = new StringBuffer();
sb.append(BOLD_OPEN).append(title).append(BOLD_CLOSE);
sb.append(BREAK);
sb.append(description);
sb.append(BREAK);
sb.append(SMALL_OPEN).append(ITALIC_OPEN).append(date).append(ITALIC_CLOSE).append(SMALL_CLOSE);
current.put("text", Html.fromHtml(sb.toString()));
current.put("imageLink", imgLink);
}
}
XML我正在解析
Gold Market Recap Reporthttp://feedproxy.google.com/~r/MetalMarketCommentary/~3/jGYtkXdSKWs/mid-session-gold_703.html
<img src="http://www.cmegroup.com/images/1x1trans.gif?destination=http://www.cmegroup.com/education/market-commentary/metals/2012/09/mid-session-gold_703.html" alt=""/>For the week December gold forged a trading range of roughly $37 an ounce. With gold prices attimes seemingly on the rocks and poised for a downside washout it was a change of pace to see afresh upside breakout in the Friday morning trade....<img src="http://feeds.feedburner.com/~r/MetalMarketCommentary/~4/jGYtkXdSKWs" height="1" width="1"/>
Fri, 21 Sep 2012 19:50:37 GMT
http://www.cmegroup.com/education/market-commentary/metals/2012/09/mid-session-gold_703.html?source=rss
2012-09-21T19:50:37Z
http://www.cmegroup.com/education/market-commentary/metals/2012/09/mid-session-gold_703.html?source=rss