大佬教程收集整理的这篇文章主要介绍了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)(<sub>)(.*?)(</sub>)","$1$3");
我的课
public class RSSReader { private final static String BOLD_OPEN = "<B>"; private final static String BOLD_CLOSE = "</B>"; private final static String BREAK = "<BR>"; private final static String ITALIC_OPEN = "<I>"; private final static String ITALIC_CLOSE = "</I>"; private final static String SMall_OPEN = "<smaLL>"; private final static String SMall_CLOSE = "</smaLL>"; public static List<JSONObject> 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<Article> articles = rh.getLatestArticles(Feed); Log.e("RSS ERROR","number of articles " + articles.size()); return fillData(articles); } private static List<JSONObject> fillData(List<Article> articles) { List<JSONObject> items = new ArrayList<JSONObject>(); 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)(<sub>)(.*?)(</sub>)","$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我正在解析
<item> <title>Gold Market Recap Report</title> <link>http://Feedproxy.google.com/~r/MetalMarketCommentary/~3/jGYtkXdSKWs/mid-session-gold_703.html</link> <description><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"/></description> <pubDate>Fri,21 Sep 2012 19:50:37 GMT</pubDate> <guid isPermaLink="false">http://www.cmegroup.com/education/market-commentary/Metals/2012/09/mid-session-gold_703.html?source=RSS</guid> <dc:date>2012-09-21T19:50:37Z</dc:date> <Feedburner:origLink>http://www.cmegroup.com/education/market-commentary/Metals/2012/09/mid-session-gold_703.html?source=RSS</Feedburner:origLink> </item>
String String = "Beginning of String....<img src=\"http://webaddress.com\" height=\"1\" width=\"1\"/>"; //Escape whatever has to be escaped System.out.println(String); int start = String.indexOf("&"); int end = String.lasTindexOf("&"); String temp = String.subString(start,(end+3)); String = String.replace(temp,""); System.out.println(String);
以上是大佬教程为你收集整理的android – 如何从字符串中删除动态字符串?全部内容,希望文章能够帮你解决android – 如何从字符串中删除动态字符串?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。