• wp7 替换掉@换成指定名字


                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; }
            }

  • 相关阅读:
    Python 正则表达式(分组)
    django 笔记
    Java代理和动态代理机制分析和应用
    Chrome浏览器如何调试移动端网页信息
    【数据分析】Excle中安装数据分析工具
    【BigData】Java基础_socket编程中使用多线程
    【BigData】Java基础_多线程
    【BigData】Java基础_socket编程
    财务报表之利润表
    资产负债表的会计恒等式
  • 原文地址:https://www.cnblogs.com/androllen/p/2950776.html
Copyright © 2020-2023  润新知