I am trying to retrieve the values of ‘Title’ using the following codes:
private void GetTweets_Click(object sender, RoutedEventArgs e)
{
WebClient client = new WebClient();
client.DownloadStringCompleted += (s, ea) =>
{
XDocument doc = XDocument.Parse(ea.Result);
XNamespace ns = "http://www.w3.org/2005/Atom";
var items = from item in doc.Descendants(ns + "entry")
select new Tweet()
{
Title = item.Element(ns + "title").Value,
Image = new Uri((from XElement xe in item.Descendants(ns + "link")
where xe.Attribute("type").Value == "image/png"
select xe.Attribute("href").Value).First<string>()),
};
foreach (Tweet t in items)
{
_tweets.Add(t);
}
};
client.DownloadStringAsync(new Uri("https://twitter.com/statuses/user_timeline/[username].atom?count=10"));
}
I was able to retrieve a list of tweets, however, I want to remove the first 16 characters displayed by the ‘Title’ value.
Is there are way to use the sub string function here?
Thank you.
Assuming that
item.Element(ns + "title").Valueis astring, you should be able to use the String.Substring(Int32) method.Be aware that this will throw an exception if the length of the Title is less than 16 characters, so it would probably be best to test for that first.