Hello! I basically have a rule that a "code" shoul...
# getting-started
c
Hello! I basically have a rule that a "code" should be 4 chars long. Always. BUT my backend sends me codes with leading 0 missing. So I need to add them back in myself. If I encounter "1", then I pad with three leading zeroes. "0001" If I encounter "22", then I pad with two leading zeroes. "0022" If I encounter "333", then I pad with one leading zeroes. "0333" I have an if statement that does that... but is there some sort of easy method in kotlin to "pad a string so that it always contains x characters, and pad it with y character?"
r
Copy code
"1".padStart(length = 4, padChar = '0') // 0001
c
lmao. i swear i google for this. google is slacking
😅 2
thank you stdlib people for thinking of everything.
d
Or just write your own version! Sorry, couldn't resist 🙂 https://qz.com/646467/how-one-programmer-broke-the-internet-by-deleting-a-tiny-piece-of-code
😅 3