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

发布于 2024-12-04 13:56:39 字数 364 浏览 1 评论 0原文

我尝试执行以下操作:

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

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

I tried to do the following :

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

and obtain

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

and so on.

I tried that:

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

but I still have a list ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌上芳菲 2024-12-11 13:56:39

也许你需要这样的东西:

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

Perhaps you require something like:

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

giving

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

or

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

giving

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文