int count = 20; //要生成20个
string s = "0123456789abcdefghjklmnpqrstuvwxyz";
char[] c = new char[5];
int counter = 0;
for (int i = 0; i < s.Length; i++)
{
c[0] = s[i];
for (int j = 0; j < s.Length; j++)
{
c[1] = s[j];
for (int k = 0; k < s.Length; k++)
{
c[2] = s[k];
for (int m = 0; m < s.Length; m++)
{
c[3] = s[m];
for (int n = 0; n < s.Length; n++)
{
if (counter == 0)
n = 1;
c[4] = s[n];
string r = new string(c);
if (counter < count)
{
FileStream fst = new FileStream(sss,FileMode.Append);
StreamWriter swt = new StreamWriter(fst,System.Text.Encoding.GetEncoding("utf-8"));
counter++;
}
else
{
i = j = k = m = n = s.Length;
break;
}
}
}
}
}
}
上面一段代码是生成一个指定数目的有序的五位格式字符串,每生成一个写入txt文档,但是如果是要生成几百万的数据,速度非常胡慢,有没有什么方式能够速度很快的,谢谢
string s = "0123456789abcdefghjklmnpqrstuvwxyz";
char[] c = new char[5];
int counter = 0;
for (int i = 0; i < s.Length; i++)
{
c[0] = s[i];
for (int j = 0; j < s.Length; j++)
{
c[1] = s[j];
for (int k = 0; k < s.Length; k++)
{
c[2] = s[k];
for (int m = 0; m < s.Length; m++)
{
c[3] = s[m];
for (int n = 0; n < s.Length; n++)
{
if (counter == 0)
n = 1;
c[4] = s[n];
string r = new string(c);
if (counter < count)
{
FileStream fst = new FileStream(sss,FileMode.Append);
StreamWriter swt = new StreamWriter(fst,System.Text.Encoding.GetEncoding("utf-8"));
counter++;
}
else
{
i = j = k = m = n = s.Length;
break;
}
}
}
}
}
}
上面一段代码是生成一个指定数目的有序的五位格式字符串,每生成一个写入txt文档,但是如果是要生成几百万的数据,速度非常胡慢,有没有什么方式能够速度很快的,谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货