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 

replace every "*" in string

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


Joined: 03 Sep 2006
Posts: 24

PostPosted: Tue Aug 05, 2008 12:22 pm    Post subject: replace every "*" in string Reply with quote

Hi,
I'm keeping the channels banlist in a text file but got a problem removing the entries from that file as I can't figure out how to escape the asterisks.

sed expects every "*" and "!" to be escaped like "\*" and "\!"

What's the easiest way to replace _every_ "*" with "\*" in a given string? (Replacing just one isn't a problem, but for 5 my code had around 50 lines and is fugly)
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Tue Aug 05, 2008 1:18 pm    Post subject: Reply with quote

Regsub with a regular expression:

Code:
set maskedString [regsub -all -- {\*|!} $oldString {\\\0}]

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
BCyo+8C4
Voice


Joined: 03 Sep 2006
Posts: 24

PostPosted: Tue Aug 05, 2008 5:59 pm    Post subject: Reply with quote

doesn't work Sad
Tcl error [delban]: wrong # args: should be "regsub ?switches? exp string subSpec varName"
Entered the command exactly like you said, only changed the variable names:
Code:
set maskedString [regsub -all -- {\*|!} $mask {\\\0}]

also tried with just "{\*}" as expression but that failed as well.
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Tue Aug 05, 2008 6:06 pm    Post subject: Reply with quote

That's odd... which version of tcl are you using?
Most versions of tcl have the varName argument optional. Nevertheless, try using something like this instead then:
Code:
regsub -all -- {\*|!} $mask {\\\0} maskedString

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
BCyo+8C4
Voice


Joined: 03 Sep 2006
Posts: 24

PostPosted: Tue Aug 05, 2008 6:14 pm    Post subject: Reply with quote

nvm, just figured it out:
Code:
regsub -all {\*|!} $mask {\\\0} mask
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