2013-09-01 126 views
0

我在C#中有一个RSS阅读器,我的问题是有些网站也在其Feed中显示图片,但我不需要它。这是如何从这个网站的新闻的描述看起来如下:使用正则表达式删除字符串的一部分

/calcio/calciomercato/2013/09/01-271389/Calciomercato?rssimage This is the actual news... 
/calcio/calciomercato/2013/08/01-271389/Notizia?rssimage This is the real news... 
/calcio/calciomercato/2013/05/01-271389/Esempio?rssimage The news... 

如何删除实际新闻之前的所有文本?所有“不需要的部分”都以“?rssimage”结尾,那么我如何才能删除所有文本?另外,如何检查新闻是否包含这些不需要的文字?

谢谢!

编辑: 这是RSS: http://tuttosport.feedsportal.com/c/34178/f/619230/index.rss

这是desided输出: 的Gli emiliani vogliono未attaccante:IL Sogno的雷斯塔Belfodil,un'ipotesi concretaè弗洛罗·弗洛雷斯,马C'èanche IL cileno dell'Universidad

我biancoscudati sognano IL格兰德COLPO:在极端情况下

operazione佩罗艰难PERCHE萨托利dovrebbe POI trovare IL sostituto PROPRIO

L'attaccante finoraèstato POCO impiegato TRA我铁托拉里,potrebbe andare票价ESPERIENZA:我friulani卤味饭能proposto人博洛尼亚TITOLO temporaneo

+0

尝试显示您想获得的欲望输出 – meda

+0

您可以发布*真实* rss和期望的输出吗? – I4V

回答

3

尝试:

string input = "/calcio/calciomercato/2013/09/01-271389/Calciomercato?rssimage This is the actual news..."; 
string output = Regex.Replace(input, @"(.*?)\?rssimage ", string.Empty); 

不要忘记在您的代码文件的操作中添加using System.Text.RegularExpressions;

+0

正是我需要的!谢谢:D。 – AshleyT

+0

@ user1100421 - 这是你想要的,不知道它是否是你需要的。 ;) – Corak

+1

@科拉克说,人们自己复杂化。这是出现“XY”问题的地方 –

3

它是如此简单,我们不需要Regex,只是一些string methods

int i = line.IndexOf("?rssimage"); 
if(i != -1) line = line.Substring(i+8).TrimStart(); 
+2

“有些人遇到问题时会想”我知道,我会用正则表达式“,现在他们有两个问题。” – Corak

相关问题