Kotlin/JS not have `String.format` or am I crazy
# javascript
i
Kotlin/JS not have
String.format
or am I crazy
h
Haha you’re not crazy, you’ll likely have to use string templates or leverage JavaScript’s string manipulation capabilities
1
a
If you need it, could you create an issue in YouTrack with a description of your use case?
a
e
Upvoted. Very useful to standardize formatting.
c
I'm curious what the use case is for it. I've yet to need it even once.
a
I use string formatting rarely, but it's a nice way to round floats to 2 decimal places (for example), or to pad strings with whitespace so multiple lines line up nicely. It's possible to do the same things with manual string manipulation, but it's more verbose, tricky, ugly. It'd also be handy to have a Kotlin Common implementation because even though each platform has string formatting, the behaviour is slightly different. For example, in Kotlin/Native string formatting is very difficult because it's very difficult to write an external function that accepts varargs (due to C limitations).
p
FTR, padding with whitespace is possible (and IMO pretty readable) with e.g. padStart, it’s available in Kotlin Common