如何在Mathematica中打印n个前导零的整数?

时间:2011-09-14 15:51:05

标签: wolfram-mathematica

我尝试执行以下操作:

Do[
  f1 = StringReplace[
    "obsxxxx.out", {"xxxx" -> ToString[i]}];
  Print[f1];
  ,
  {i, 200}];

并获得

obs0001.out
obs0002.out
...
obs0010.out
...
obs0100.out
...

等等。

我试过了:

ToString[Flatten[IntegerDigits[20, 10, 4]]]

但我还有一份清单......

1 个答案:

答案 0 :(得分:22)

也许您需要以下内容:

Table[IntegerString[i, 10, 4], {i, 1, 10}]

{"0001", "0002", "0003", "0004", "0005", "0006", "0007", "0008", 
"0009", "0010"}

Table["obs" <> IntegerString[i, 10, 4] <> ".out", {i, 1, 10}]

  

{“obs0001.out”,“obs0002.out”,“obs0003.out”,“obs0004.out”,   “obs0005.out”,“obs0006.out”,“obs0007.out”,“obs0008.out”,   “obs0009.out”,“obs0010.out”}