![[Kotlin]0パディングした文字列を返すExtension](https://www.yukiiworks.com/wp-content/uploads/2019/04/kotlin.png)
はじめに
KotlinにてInt型の数値を指定桁数でゼロパディングした文字列を返すExtensionを作成しました。
コード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /** * 指定桁数で0パディングした文字列を返す * @param length 桁数 * @return 0パディングした文字列 */ fun Int.zeroPadding(length: Int): String { var target = this.toString() val remaining = length - target.length if (remaining > 0) { for (i in 1..remaining) { target = "0${target}" } } return target } |
拡張として作成することでInt型の変数でどこでも使えます!
![[Flutter]Navigatorで2つ前の画面に戻る方法](https://www.yukiiworks.com/wp-content/uploads/2020/08/flutter-300x144.png)
![[Docker]different lower_case_table_names settings for server ('1') and data dictionary ('0').エラーでコンテナが起動できない問題について](https://www.yukiiworks.com/wp-content/uploads/2019/08/docker-logo-2-150x150.png)
![[Android]ListViewで区切り線を消す方法](https://www.yukiiworks.com/wp-content/uploads/2019/04/android-150x150.jpg)
![[Laravel][mailtrap]Expected response code 354 but got code ''550'', with message ''550 5.7.0 Requested action not taken: too many emails per second ''エラーについて](https://www.yukiiworks.com/wp-content/uploads/2019/05/laravel-150x150.png)
![[iOS]Can’t end BackgroundTask: no background task exists with identifier 1 (0x1), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.エラーについて](https://www.yukiiworks.com/wp-content/uploads/2019/09/Xcode-150x150.png)

![[Flutter]chopper_generator使用時にbuild_runnerのビルドが完了しない問題の解消法](https://www.yukiiworks.com/wp-content/uploads/2020/08/flutter-150x150.png)
![[Swift]UITextViewでリンクはタップできるまま長押しとダブルタップでの選択を防ぐ方法](https://www.yukiiworks.com/wp-content/uploads/2019/04/swift-150x150.png)
