How to get twitter user ID in content

Dec 9, 2014 at 6:04 PM
the twitter user ID starts with @ then at least one character, after with characters, numbers and maybe underscores.

how to get twitter user ID by using RegEx in C#? and simply replace them by first 1 or 2 characters? thanks
Dec 9, 2014 at 6:12 PM
Hey not sure if it works for your case, but try using the UserMentions property of the tweet.

Dec 9, 2014 at 6:22 PM
Edited Dec 9, 2014 at 6:22 PM
thanks, seems I will have to deal with a list to make this replacing working. My original thought is the RegEx replace to handle it in String manipulation.
any thoughts?
Dec 9, 2014 at 6:26 PM
let us say:
What if I just and still want the @ABED_12 be replaced as AB, how to handle it with RegEx replacing or RegEx in C#?
Dec 9, 2014 at 6:42 PM
The regex pattern "@[\w_]*" should match valid usernames. However, I'm not sure about replacing it. I don't know why you're so inclined towards regex, but here's a solution using UserMentions.
var tweet = Tweet.GetTweet(542395911025213440);
var txt = tweet.Text;
tweet.UserMentions.Select(u => u.ScreenName).ForEach(u => txt = txt.Replace("@" + u, u.Substring(0, 2)));
Marked as answer by linvi on 12/10/2014 at 11:00 AM
Dec 9, 2014 at 7:12 PM
thank you. man. THAT WAS EASY.

I made things a little complex-ed. that is all.

another issue for ForEach
Error 1 'System.Collections.Generic.IEnumerable<string>' does not contain a definition for 'ForEach' and no extension method 'ForEach' accepting a first argument of type 'System.Collections.Generic.IEnumerable<string>' could be found (are you missing a using directive or an assembly reference?)

what to do?
Dec 9, 2014 at 9:20 PM
ForEach is not available for tweet.UserMentions. I don't know why?
Dec 10, 2014 at 8:34 AM
You probably miss the Extensions namespace.
using Tweetinvi.Core.Extensions;
Dec 10, 2014 at 4:21 PM
Edited Dec 10, 2014 at 4:24 PM
got it, thanks