【问题标题】:How to print an integer with n leading zeros in Mathematica?如何在 Mathematica 中打印具有 n 个前导零的整数?
【发布时间】:2011-09-14 15:51:04
【问题描述】:

我尝试执行以下操作:

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]]]

但我还有一份清单……

【问题讨论】:

标签: wolfram-mathematica


【解决方案1】:

也许你需要类似的东西:

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"}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-21
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 2012-01-14
    • 1970-01-01
    • 2015-06-12
    相关资源
    最近更新 更多