C# - Parse Twitter HashTag to link

If you want to add the hashtogs from Twitter timeline , here's how you want to do :


protected string TwitterHashTag(string txt)
{
    string HashTagPattern = @"#([A-Za-z0-9\-_&;]+)";

    if (txt.Contains("#"))
    {
        var names = new List<string>();
        foreach (Match match in Regex.Matches(txt, HashTagPattern))
        {
            var hashTag = match.Groups[1].Value;
            if (!names.Contains(hashTag))
            {
                names.Add(hashTag);
                txt = txt.Replace("#" + hashTag,
                    String.Format("<a href=\"http://twitter.com/search?q={0}\" target='_blank'>#{1}</a>",
                    HttpUtility.UrlEncode("#" + hashTag), hashTag));
            }
        }
    }
    return txt;
}