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.
Help for those learning Tcl or writing their own scripts.
-
gonzo
- Voice
- Posts: 2
- Joined: Sat Dec 03, 2005 2:05 pm
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!
-
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
-
gonzo
- Voice
- Posts: 2
- Joined: Sat Dec 03, 2005 2:05 pm
Post
by gonzo »
thx demond!