PHondogo
ephemient
CLOVIS
fun String.format(vararg args: Any?): String = buildString { var index = 0 var position = 0 while (position < this@format.length) { val next = this@format.indexOf('%', startIndex = position) if (next < 0) break append(this@format.substring(position, next)) when (val c = this@format.getOrNull(next + 1)) { '%' -> append('%') 's' -> append(args[index++]) 'd' -> append((args[index++] as Number).toInt()) 'l' -> append((args[index++] as Number).toLong()) 'e', 'f', 'g' -> append((args[index++] as Number).toDouble()) else -> throw IllegalArgumentException(if (c == null) "%" else "%$c") } position = next + 2 } append(this@format.substring(position)) }
A modern programming language that makes developers happier.