SoFunction
Updated on 2025-03-06

C# Implementation method of blocking keywords

/// <summary>
/// Mask illegal strings (if there are illegal characters, then use "***" to replace them)
        /// </summary>
/// <param name="strText">String to be detected</param>
/// <returns>Return a healthy character</returns>
        public static string CheckKeyword(string strText)
        {
IList<string> list = new List<string>();     //Instantiate a data set
string strpath = ("function/");   //Get the text document path
            int a =("IFSns");   
            int b =("function");
            string m = (a+5, b - a - 6);
string PathTxt = (m, "");    //Get the relative path to call this method
FileStream fs = new FileStream(PathTxt, , );  //Open the txt document and save the data to the file stream
StreamReader reader = new StreamReader(fs, ); //File reading
            string strLine = ();
while (strLine!=null&& != 0)    //There is data
            {
(().Replace(" ",""));     //If the read data has spaces, delete the spaces and save them to the string dataset
strLine = ();   //Every time you read, continue reading from the next line of the line
            }
(); //Close the file stream
foreach (string str in list) //Loop through file stream
            {
                if ((str))   
                {
                    int lg = ;
                    string sg = "";
                    for (int i = 0; i < lg; i++)
                    {
                        sg+="*";
                    }
strText = (str, sg); //If you contain keywords in the txt document, replace them with "***"
                }
            }
            return strText;
        }