我需要找到一种方法来在指定的字符串而不是开头开始这个字符串生成算法。例如,不是从 'aaaa' 开始,而是从 'baxi' 开始,然后遍历字符串空间的其余部分。
private static String Charset = "abcdefghijklmnopqrstuvwxyz";
/// <summary>
/// Start Brute Force.
/// </summary>
/// <param name="length">Words length.</param>
public static void StartBruteForce(int length)
{
StringBuilder sb = new StringBuilder(length);
char currentChar = Charset[0];
for (int i = 1; i <= length; i++)
{
sb.Append(currentChar);
}
int counter = 0;
ChangeCharacters(0, sb, length, ref counter);
Console.WriteLine(counter);
}
private static void ChangeCharacters(int pos, StringBuilder sb, int length, ref int counter)
{
for (int i = 0; i <= Charset.Length - 1; i++)
{
sb[pos] = Charset[i];
if (pos == length - 1)
{
counter++;
Console.WriteLine(sb.ToString());
}
else
{
ChangeCharacters(pos + 1, sb, length, ref counter);
}
}
}