【发布时间】:2015-12-20 04:25:47
【问题描述】:
我有一个文件转换实用程序,它可以提取文件中的页面并保存在固定的 6 位数文件名中,例如:
000001.jpg - first page of file
000002.jpg - second page of file
...
000010.jpg - tenth page of file
000011.jpg - eleventh page of file
000100.jpg - hundredth page of file
000101.jpg - and so on...
...
001000.jpg
001001.jpg
...
...
999999.jpg - upto the maximum 999999th page. (6 digits max)
等等
我的意思是当文件编号达到额外数字时,前面的 0 数字被消除。文件名将始终为从000001.jpg 到999999.jpg 的6 位数字
现在,在我的代码中,我试图读取所有文件。我正在使用带有从 1 到 999999 的计数器的 for 循环来读取文件名。但是当我使用File.Read("00000" + iCount + ".jpg"); 时,它会在 for 循环计数器为 10 时出错,因为它变成 7 位数字:0000010.jpg 并且文件名无效。就像当计数器为 100 时它变成 8 位数。
如何在我的 for 循环中以有效的方式生成文件名?
【问题讨论】:
-
不懂 C#,但你能用this 填充它。
name.PadLeft(6, '0');(name是01、100等) -
@pushkin 谢谢,我现在就试试。我错过了技术/关键字“填充”:) 因为我不知道要搜索什么来解决我的问题。