整理和重新建立关键词

2015-11-28 17:12:22  访问(2123) 赞(0) 踩(0)


        /// <summary>
        /// 整理和重新建立关键词
        /// </summary>
        /// <param name="sortName"></param>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string KeyWordRebuild
            (
                string sortName,
                string str
            )
        {
            if (sortName == null)
                sortName = "";
            else
                sortName = sortName.Trim();

            if (str == null || str.Length == 0)
                return sortName;

            str = sortName + "," + str.Replace(",", ",");
            string[] sA = str.Split(',');

            List<string> sL = new List<string>();
            StringBuilder theResult = new StringBuilder();
            bool isFirst = true;
            string strTmp = null;
            string strLowerTmp = null;

            foreach (string s in sA)
            {
                if (s == null || s.Length == 0)
                    continue;

                strTmp = s.Trim();

                if (strTmp.Length == 0)
                    continue;

                strLowerTmp = strTmp.ToLower();

                if (sL.Contains(strLowerTmp))
                {
                    continue;
                }

                sL.Add(strLowerTmp);

                if (isFirst)
                    isFirst = false;
                else
                    theResult.Append(",");

                theResult.Append(strTmp);
            }

            return theResult.ToString();

        }


标签:整理和重新建立关键词 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)