string source = "欢迎大家来吐槽~选中即可得到1副《腾讯数码扑克牌》,请本期被选中评论的网友@wangli_1355、@se7en_3、@wang189xun、@buyken1qw、@Q_chenbing、@Tuccuay 将详细地址私信大叔~";
List<User> lus = new List<User>();
lus.Add(new User() { name = "wangli_1355", nick = "王立" });
lus.Add(new User() { name = "se7en_3", nick = "冬冬" });
lus.Add(new User() { name = "wang189xun", nick = "王笑洋" });
lus.Add(new User() { name = "buyken1qw", nick = "实用美白术" });
lus.Add(new User() { name = "Q_chenbing", nick = "小小小小林" });
lus.Add(new User() { name = "Tuccuay", nick = "周力" });
string am= AccountMatch(source, lus);
private string GetMatchs(string content, List<User> luser)
{
string nsr = content;
if (!string.IsNullOrEmpty(content) && content.Contains("@"))
{
string[] sr = content.Split('@');
foreach (User us in luser)
{
for (int i = 0; i < sr.Length; i++)
{
if (sr[i].Contains(us.name))
{
nsr = nsr.Replace(us.name, us.nick);
}
}
}
nsr = nsr.Replace("@", "");
}
return nsr;
}
public string AccountMatch(string Data, List<User> luser)
{
return GetMatchs(Data, luser);
}
public class User
{
public string name { get; set; }
public string nick { get; set; }
}