且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在许多字符串中找到模式并替换它们?

更新时间:2023-02-06 17:05:19

试试这个



try this

static void Main(string[] args)
   {


       string[] myArray = { "Can", "you", "help me", "please", "?", "thank", "you", "very much", "." };
       ReplaceWithNON(myArray);


   }

   private static void ReplaceWithNON(string[] myArray)
   {
       string[] patterns = { "the", "that", "(eg width)", "123", ".", "text", "for example", "help me", "very much" };

       for (int i = 0; i < myArray.Length; i++)
       {
           if (patterns.Contains(myArray[i]))
               myArray[i] = "NON";
       }
   }