蛮力从数组中添加字符?如何

Brut force add characters from array? how to

我在 try catch 和 final 块中有一个函数我知道该函数将始终使用 finally 代码块但是这里它应该添加字符 我不想使用 while 循环

 string increse_me ;
 public void brut()
 {
     string[] small = new string[] { "a", "b", "c", "d", "e", "f", "g",   "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
     string[] cap = new  string []  {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
     string[] num = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
     string[] spcl = new string[] { "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "`", ">", "<", "+" };

   if( textbox1.Text == increase_me)
   {
       messagebox.show("matched")
   }
  catch (exception ex) 
  {
  }  
  finally 
  {  
      brut();
     //here i have to call function again with increase letter as start from "a"it add next to it
  }
}

现在如何创建一个函数,该函数首次使用声明为 increase_me 的字符串,并在最终从第二个数组失败时增加其值,依此类推 最大26位数

在直观的层面上,您可以只传入一个数组和字符串,然后 return 一个更新后的字符串并附加第一个元素:

string stringUpdate(string update, string[] toAdd) 
{
     if (toAdd!=null && toAdd.length>0) {
          return update+toAdd[0];
     }
     return update;
}

这将使 brut() 必须聪明地知道将什么传递给函数,这样它就不会传递空数组,尽管它只是 return 第一个字符串,如果是的话案子。当然,这只是整体解决方案的一部分,因为我怀疑正则表达式是一个更容易使用的解决方案,但并没有被问到。