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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -