listarraylisttcltk-toolkittcltk

How to give dynamic varying space between words in Tcl?


I'm new to tcl ,I like your help to give a dynamic variable spacing between words in Tcl. Example : "Stack over flow" " Stack" as 5 letter in it. So I have to give space of 5 to start next word same goes to next word.

Output: Stack     over    flow

Solution

  • I suppose you could do something like this:

    set example "Stack over flow"
    set result ""
    
    foreach word $example {
        append result $word [string repeat " " [string length $word]]
    }
    
    set result [string trim $result]
    puts $result
    

    Will give:

    Stack     over    flow