首先检查它的格式是否正确,然后:
static readonly List<char> alphabetUpper = new List<char> { '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' };
static public IEnumerable<string> GetRange(string arg)
{
arg = arg.ToUpperInvariant();
string[] ranges = arg.Split(':');
ulong range0 = ulong.Parse((new string((from char c in ranges[0] where char.IsDigit(c) select c).ToArray())));
ulong range1 = ulong.Parse ((new string((from char c in ranges[1] where char.IsDigit(c) select c).ToArray())));
ranges[0] = new string((from char c in ranges[0] where !char.IsDigit(c) select c).ToArray());
ranges[1] = new string((from char c in ranges[1] where !char.IsDigit(c) select c).ToArray());
IEnumerable<int> arrayindexes0 = from c in ranges[0] select alphabetUpper.IndexOf(c);
IEnumerable<int> arrayindexes1 = from c in ranges[1] select alphabetUpper.IndexOf(c);
foreach (IEnumerable<int> f in (from i in arrayindexes0 from e in arrayindexes1 select new List<int>() {i, e}))
{
foreach (int i in f)
{
foreach (ulong o in LongRange(range0, range1))
{
yield return alphabetUpper[i] + o.ToString();
}
}
}
}
static IEnumerable<BigInteger> LongRange (BigInteger first, BigInteger second)
{
BigInteger difference = second - first;
for (BigInteger i = 0; i <= difference; i++)
{
yield return first + i;
}
}
目前适用于单字母,我正在努力让更多行发生。