Padding string in Kotlin -
i trying pad string in kotlin achieve proper alignment on console output. along these lines:
accountsloopquery - "$.contactpoints.contactpoints[?(@.contactaccount.id)]" brokerpassword - ***** brokeruri - tcp://localhost:61616 brokerusername - admin contactpointpriorityproperties - "contactpointpriority.properties" customercollection - "customer" customerhistorycollection - "customer_history" defaultsystemowner - "tuigroup" i have ended coding way - cheating java's string.format:
mutablelist.foreach { cp -> println(string.format("%-45s - %s", cp.name, cp.value)) } is there proper way kotlin libraries?
you can use .padend(length, padchar = ' ') extension kotlin-stdlib that. accepts desired length , optional padchar (default whitespace):
mutablelist.foreach { println("${it.name.padend(45)} - ${it.value}") } there's padstart aligns padding in other direction.
Comments
Post a Comment