1. 程式人生 > 實用技巧 >C#處理字串

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