C#过滤特定字符串

it2022-05-24  79

/**/ /// <summary>        /// 检测输入字符串strInput是否在禁用字符串strConfigWords中存在,存在则过滤该输入值。        /// </summary>          public   string  CheckRepWords( string  strConfigWords, string  strInput)         {            //创建strWords数组,以“|”号为分割符。            string[] strWords = strConfigWords.Split(new char[] {'|'});            //依此读取数组中各个单元,并检测该字符串是否存在于以定义过滤词组strConfigWords中,            //strConfigWords一行内的格式为:“str1,str2”,若str1存在于输入内容strInput内,            //则将str1替换为str2。            foreach(string strWord in strWords)            {                string[] strSplitWord = strWord.Split(new char[] {','});                if(strInput.IndexOf(strSplitWord[0])>=0)                {                    strInput = strInput.Replace(strSplitWord[0],strSplitWord[1]);                }            }            return strInput;        }

转载于:https://www.cnblogs.com/lgzdd/archive/2005/07/31/204013.html


最新回复(0)