C# 关键字替换

        /// <summary>
        /// 关键字替换
        /// </summary>
        /// <param name="body"></param>
        /// <returns></returns>
        public string TagReplace(string body)
        {
            string[] begin = this.txtTagBegin.Text.Split('|');
            string[] end = this.txtTagEnd.Text.Split('|');
            string a = string.Empty, b = string.Empty;

            for (int i = 0; i < begin.Length; i++)
            {
                a = begin[i];//第一个关键字
                if (!string.IsNullOrEmpty(a))//不为空
                {
                    try
                    {
                        b = end[i];//替换字符为空
                    }
                    catch { }
                    body = body.Replace(a, b);
                }
            }
            return body;
        }

  

posted @ 2017-06-12 10:00  懒人境界  阅读(4353)  评论(0编辑  收藏  举报