你好我試圖讓所有可能的組合重複給定的字符數組。 字符數組由字母組成(只有更低),我需要生成長度爲30或更多字符的字符串。C#字符在一大組字符上的重複排列
我嘗試了很多for循環的方法,但是當我嘗試獲取char數組中字符長度超過5的所有char組合時,我得到了內存異常。
所以我創建了類似的方法,只需要第一個200000字符串,然後下一個2000000等等,這被證明成功,但只有較小的長度的字符串。
這是我的方法有7個字符長度:
public static int Progress = 0;
public static ArrayList CreateRngUrl7()
{
ArrayList AllCombos = new ArrayList();
int passed = 0;
int Too = Progress + 200000;
char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToLower().ToCharArray();
for (int i = 0; i < alpha.Length; i++)
for (int i1 = 0; i1 < alpha.Length; i1++)
for (int i2 = 0; i2 < alpha.Length; i2++)
for (int i3 = 0; i3 < alpha.Length; i3++)
for (int i4 = 0; i4 < alpha.Length; i4++)
for (int i5 = 0; i5 < alpha.Length; i5++)
for (int i6 = 0; i6 < alpha.Length; i6++)
{
if (passed > (Too - 200000) && passed < Too)
{
string word = new string(new char[] { alpha[i], alpha[i1], alpha[i2], alpha[i3], alpha[i4], alpha[i5],alpha[i6] });
AllCombos.Add(word);
}
passed++;
}
if (Too >= passed)
{
MessageBox.Show("All combinations of RNG7 were returned");
}
Progress = Too;
return AllCombos;
}
我試着用上面,所以我將得到與30,但lenghts串所描述的方法添加30 for循環應用程序只是hangs.Is有什麼更好的方法來做到這一點?所有的答案將不勝感激。先謝謝你!
有人可以請只是發佈方法它如何處理更大的legth字符串我只是想看到一個例子?我不必存儲這些數據,我只需要將其與某些內容進行比較並從內存中釋放它。我用字母表例如我不需要整個字母表。問題不是需要多長時間或多少組合纔會是!
你想要每個長度超過30的char數組組合嗎?祝你好運!你很快就需要它嗎? – AndrewC
我可以訪問大量的計算機。我只需要一個示例方法。 – formatc
你的確意識到它最終會是'30!'不同的字符串,每個長度都是30 * 1.6 * 10^34字節。除非你是谷歌,否則你不能存儲(如果他們可以的話) –