search
LoginSignup
1

More than 1 year has passed since last update.

先頭に0を埋めたいことありませんか?
ありますよね?

@tksmaru さんの言語別 0埋め数字を作成する方法 みたいな感じのことです。

たとえばRuby

irb(main):001:0> '%04d' % 55
=> "0055"

Elixirではどうやればいいのでしょうか:interrobang:

String.pad_leading/3

example

iex> String.pad_leading("55", 4, "0")
"0055"

iex> String.pad_leading("abc", 5)
"  abc"

iex> String.pad_leading("abc", 4, "12")
"1abc"

iex> String.pad_leading("abc", 6, "12")
"121abc"

iex> String.pad_leading("abc", 5, ["1", "23"])
"123abc"

お仲間にString.pad_trailing/3があります

Wrapping Up :christmas_tree::santa::santa_tone1::santa_tone2::santa_tone3::santa_tone4::santa_tone5::christmas_tree:

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
1