C# 暴力从数组中添加字符?如何

C# 暴力从数组中添加字符?如何,c#,.net,combinations,brute-force,C#,.net,Combinations,Brute Force,我在try-catch和final-block中有一个函数,我知道该函数将始终使用finally代码块,但在这里它应该添加字符我不想在while-loop中使用 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", "

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

 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
  }
}
字符串递增;
public void brut()
{
字符串[]小=新字符串[]{“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”};
字符串[]cap=新字符串[]{“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”};
字符串[]num=新字符串[]{“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”、“0”};

string[]spcl=newstring[]{“!”、“@”、“#”、“$”、“%”、“^”、“&”、“*”、“(“,”)、“`”、“>”、“在直观的层面上,您只需传入一个数组和字符串,然后返回一个添加了第一个元素的更新字符串:

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

这将使
brut()成为
必须对传递到函数中的内容保持明智,这样它就不会传递空数组,尽管如果是这样,它只会返回第一个字符串。当然,这只是整体解决方案的一部分,因为我怀疑正则表达式在这里是一个更简单的解决方案,但如果您想编写方法将字符串移动到每次调用的下一个排列中,您必须检查当前字符串的最后一个字符(例如
“asd123B!”
)并实现滚动(
“B+”
变为
“Ca”
).这是可行的,但我希望您不要期望我们为您编写该方法。您知道这会因为无限递归而出现堆栈溢出问题,对吗?很难说您在问什么,但我认为您只是在寻找类似于“"查看过
String.Join
方法吗?如果目的是将small、cap、num和spcl数组中的字符串添加到
incremese\u me
,则可以在每个数组上使用Join方法添加到incremese\u me,前提是需要一个块事务。如果重复逐个执行每个字符串,则循环可能是必需的,除非您想编写一些非常难看的递归函数,以便在不断缩小的数组中传递以添加值,而这将是您可以采取的另一条路径。