C#处理字符串

 public static string FreshString(string str,string cSub)
        {
            if (string.IsNullOrEmpty(str))
                return "";
            if (string.IsNullOrEmpty(cSub))
                throw new Exception("can not unll");
            if (str.Contains(cSub))
                throw new Exception(str+"含有"+ cSub);
            string temp = string.Empty;
            char[] strArry = new char[] { '^', '&', '$', '#', '@', '`' };
            foreach (char tempSub in strArry)
            {
                if (!str.Contains(tempSub))
                {
                    List<string> listPn = new List<string>();
                    listPn = str.Replace(' ', tempSub).Replace("\r\n", tempSub.ToString())
                        .Replace('\t', tempSub).Replace('\n', tempSub)
.Replace("\u00A0",tempSub.ToString())//\u00A0是ASCII=160特殊空格nbsp
.Split(tempSub).ToList(). Where(x
=> !string.IsNullOrEmpty(x.Trim())).ToList(); temp = string.Join(cSub, listPn.Select(x => x)); break; } } return temp; }

 

posted @ 2020-07-24 17:12  王小鹏  阅读(157)  评论(0编辑  收藏  举报