Say I have a string like this:
set str "AAA B C DFG 142 56"
Now I want to get a list as follows:
{AAA B C DFG 142 56}
For that I want to use split function, but in that case I get some extra empty lists {}. How I can get the list above?
set text "Some arbitrary text which might include \$ or {"
set wordList [regexp -inline -all -- {\S+} $text]
See this: Splitting a String Into Words.
You can always do the following:
set str "AAA B C DFG 142 56"
set newStr [join $str " "]
It will output the following:
{AAA B C DFG 142 56}
The textutil::split module from tcllib has a splitx
proc that does exactly what you want
package require textutil::split
set result [textutil::split::splitx $str]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With