00000000
00000001
00000002
00000003
00000004
......
99999999
正好一億行
我用批處理生成速度好慢,請問用C#能快速實現嗎?
FileStream fs = new FileStream("D:\target.txt", FileMode.Append);
StreamReader sr = new StreamReader(fs);
for(int64 i = 1; i < 100000000; i++)
{
string str = int64ToStr(i);
sr.WriteLine(str);
}
sr.Close();
fs.Close();
public string int64ToStr(int64 intNum)
{
string targetStr = string.Empty;
int bits = CalcIntBit(intNum);
switch(bits)
{
case 1:
targetStr = "0000000" + intNum.ToString();
break;
case 2:
targetStr = "000000" + intNum.ToString();
break;
case 3:
targetStr = "00000" + intNum.ToString();
break;
case 4:
targetStr = "0000" + intNum.ToString();
break;
case 5:
targetStr = "000" + intNum.ToString();
break;
case 6:
targetStr = "00" + intNum.ToString();
break;
case 7:
targetStr = "0" + intNum.ToString();
break;
case 8:
targetStr = intNum.ToString();
break;
default:
break;
}
return targetStr;
}
public int CalcIntBit(int64 intNum)
{
int64 tmp = intNum/10;
int bits = 1;
while(tmp)
{
tmp =/ 10;
Bits++;
}
return Bits;
}