2013-09-01 174 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

相關問題