egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

split 1 string to "many" strings

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
gonzo
Voice


Joined: 03 Dec 2005
Posts: 2

PostPosted: Sat Dec 03, 2005 2:18 pm    Post subject: split 1 string to "many" strings Reply with quote

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 Smile
how do i extract the first word of text4 only?

thanx for your help!
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Sat Dec 03, 2005 3:58 pm    Post subject: Reply with quote

Code:

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:

foreach word [split $text] {lappend x [string trim $word {{}}]}

_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
gonzo
Voice


Joined: 03 Dec 2005
Posts: 2

PostPosted: Sun Dec 04, 2005 7:43 am    Post subject: Reply with quote

thx demond!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber