0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Kotlin 頭をゼロ埋めにする

Posted at

頭をゼロ埋めにする方法です。
padStartというものがあります。

.kt
val padWithZero = "125".padStart(5, '0')
println("'$padWithZero'") // '00125'

padStartの引数

  • length
    希望する文字列の長さ
  • padChar文字列の長さが指定された長さより短い場合に、文字列を埋め込む文字。デフォルトで はスペースが使用されます

こちらで頭をゼロ埋めにすることができます。この方法を使えば0以外も頭埋めすることが可能です。

リファレンス

0
0
0

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
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?