2012-09-03 63 views
0

我想知道是否有可能從Twitter RSS切斷網名 當前格式是這樣ASP.NET獲取Twitter的RSS網名

<item> 
    <title>USERNAME: blahblahblah </title> 
    <description>USERNAME: blahblahbla x5 blahblahbla x10 blahblahbla x15</description> 
    <pubDate>Mon, 20 Jan 2012 12:00:00 +0000</pubDate> 
    <guid>http://twitter.com/USERNAME/blahblahbla </guid> 
    <link>http://twitter.com/USERNAME/blahblahbla </link> 
    <twitter:source>please ignore here :-) </twitter:source> 
    <twitter:place/> 
</item> 

任何方式剛剛得到的用戶名,例如從「description」標記中,獲取冒號前面的文本(USERNAME)?

我真的很新的ASP.NET,感謝有點詳細信息

非常感謝

+0

這是什麼輸入?你是從一個原始的XML字符串開始的嗎?它是序列化對象的一部分嗎? –

回答

1

這個XPath表達式應該得到你想要的你想要:

<%#XPath("substring-before(description, \":\")")%> 

這裏我假設XMLDatasource看起來像:

<asp:XmlDataSource 
    runat="server" 
    ID="XmlDataSource1" 
    XPath="item" 
    DataFile="myfile.xml" /> 
+0

這正是我要找的,非常感謝吉姆! :-) – olo

1

你可以使用正則表達式:

string InnerText = "USERNAME: blahblahblah"; 

Match match = Regex.Match(InnerText, "^(.*):"); 
string username; 
if (match.Success) 
{ 
    username = match.Groups[1].Value; 
}