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 

Help with splitup a line!

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


Joined: 02 Jun 2008
Posts: 1

PostPosted: Mon Jun 02, 2008 4:29 am    Post subject: Help with splitup a line! Reply with quote

I have this in a variable $line
Code:

KuBuntU!~KuBuntU@xxxxxx.eu User: KuBuntU     IRC: KuBuntU!~KuBuntU@xxxxxx.eu 


and i wanted this splited up as variable.
$ircidentnow $username $savedircident

the User: and IRC: i not want in any of variables.
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Mon Jun 02, 2008 6:20 am    Post subject: Re: Help with splitup a line! Reply with quote

KuBuntU wrote:
I have this in a variable $line
Code:

KuBuntU!~KuBuntU@xxxxxx.eu User: KuBuntU     IRC: KuBuntU!~KuBuntU@xxxxxx.eu 


and i wanted this splited up as variable.
$ircidentnow $username $savedircident

the User: and IRC: i not want in any of variables.


Code:
regexp -- {(.+?)\sUSER\:\s(.+?)\sIRC\:\s(.+?)} $line -> ircidentnow username savedircident

-- or like this --
Code:
regsub -all {(?:USER\:\s|IRC\:\s|\s\s)} $line "" line
set ircidentnow [lindex [split $line] 0]
set username [lindex [split $line] 1]
set savedircident [lindex [split $line] 2]

Could've used 'scan' to do this as well, maybe. The top is easiest to accomplish, but if it cannot match this will not associate to any variables (it CAN fail). Eventually tcl errors or work arounds involving variables with empty contents/info exists checks will be required since at times this regexp pattern might not fit and run into code needing these variables.

The bottom way is better (it CANNOT fail). It removes user:, irc:, and double spacing from $line. Then when it splits $line to form the list it aligns perfectly to your variable assignments.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Jun 02, 2008 3:32 pm    Post subject: Reply with quote

Using [scan] it can be done like this:
Code:
scan $line "%s User: %s IRC: %s" ircidentnow username savedircident

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
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