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).Split(tempSub).ToList().
                        Where(x => !string.IsNullOrEmpty(x.Trim())).ToList();
                    temp = string.Join(cSub, listPn.Select(x => x));
                    break;
                }
            }
            return temp;
        }

猜你喜欢

转载自www.cnblogs.com/wangjp-1233/p/13373018.html
今日推荐