This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

split 1 string to "many" strings

Help for those learning Tcl or writing their own scripts.
Post Reply
g
gonzo
Voice
Posts: 2
Joined: Sat Dec 03, 2005 2:05 pm

split 1 string to "many" strings

Post by gonzo »

First of all: i only did very little tcl programming so far and couldn't find a solution to my problem in the forum and the tcl FAQ...

problem:
i have one string which looks like
{some numbers} {text1} {text2} {text3} {text4}

and i want every "information" between { } as a seperate string:
a = "some numbers"
b = "text1"....

i played around with string last/first and string range, but was only able to get the first ("some numbers") and the last ("text4") part.


bonus question :)
how do i extract the first word of text4 only?

thanx for your help!
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

foreach {foo word} [regexp -all -inline {{(.*?)}} $text] {lappend x $word}
then in x you have a list of the strings you need

or you can strip braces from each word (but this won't work if you lack spaces):

Code: Select all

foreach word [split $text] {lappend x [string trim $word {{}}]}
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
g
gonzo
Voice
Posts: 2
Joined: Sat Dec 03, 2005 2:05 pm

Post by gonzo »

thx demond!
Post Reply