zoukankan      html  css  js  c++  java
  • C#去掉字符串中的特殊字符

    方案一:

    string except_chars = ": ‘ ! @ # % … & * (  ^  &  ¥  , 。 , .)$";
    string src = "就是包含: 这些‘字符 包含空格)都要$去掉么?";
    string result = Regex.Replace(src, "[" + Regex.Escape(except_chars) + "]", "");

    方案二:

    //只保留字母、数字 和汉字

    string strAfter= Regex.Replace(strBefor, @"[^a-zA-Z0-9u4e00-u9fa5s]", "");

    实例:

            /// <summary>
            /// 判断该样本商品是否已存在
            /// </summary>
            /// <param name="model"></param>
            /// <returns>存在:true</returns>
            public bool IsExist(ClassifyCorrectionPanelPool model)
            {
                bool isExist = false;
                List<ClassifyCorrectionPanelPool> modelList = LoadEntities(a => a.CODE_TS.Equals(model.CODE_TS) && a.G_NAME.Equals(model.G_NAME)).ToList();
    
                if (modelList.Count > 0)
                {
                    foreach (var item in modelList)
                    {
                        string GModelrep = Regex.Replace(item.G_MODEL, @"[^a-zA-Z0-9u4e00-u9fa5s]", "");
    
                        string addGModelRep = Regex.Replace(model.G_MODEL, @"[^a-zA-Z0-9u4e00-u9fa5s]", "");
    
                        if (GModelrep.Equals(addGModelRep))
                        {
                            isExist= true;
                        }
                    }
                }
                return isExist;
            }
  • 相关阅读:
    lc739
    POJ3280
    6.2
    5.30
    5.28
    5.26
    5.26
    5.25
    从0搭建vue项目
    docker安装jenkins并使用
  • 原文地址:https://www.cnblogs.com/xiaoerlang90/p/4372290.html
Copyright © 2011-2022 走看看