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

Ced*_* H. 10 wolfram-mathematica

我试着做以下事情:

Do[
  f1 = StringReplace[
    "obsxxxx.out", {"xxxx" -> ToString[i]}];
  Print[f1];
  ,
  {i, 200}];
Run Code Online (Sandbox Code Playgroud)

并获得

obs0001.out
obs0002.out
...
obs0010.out
...
obs0100.out
...
Run Code Online (Sandbox Code Playgroud)

等等.

我试过了:

ToString[Flatten[IntegerDigits[20, 10, 4]]]
Run Code Online (Sandbox Code Playgroud)

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

tom*_*omd 22

也许你需要这样的东西:

Table[IntegerString[i, 10, 4], {i, 1, 10}]
Run Code Online (Sandbox Code Playgroud)

{"0001", "0002", "0003", "0004", "0005", "0006", "0007", "0008", 
"0009", "0010"}
Run Code Online (Sandbox Code Playgroud)

要么

Table["obs" <> IntegerString[i, 10, 4] <> ".out", {i, 1, 10}]
Run Code Online (Sandbox Code Playgroud)

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