Warm tip: This article is reproduced from stackoverflow.com, please click
list split tcl whitespace

split string by arbitrary number of whitespaces to a list

发布于 2020-04-20 09:44:23

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?

Questioner
Narek
Viewed
30
32.8k 2012-09-24 14:40
set text "Some arbitrary text which might include \$ or {"
set wordList [regexp -inline -all -- {\S+} $text]

See this: Splitting a String Into Words.