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.

string map question

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
droolin
Halfop
Posts: 64
Joined: Thu Jul 24, 2003 9:07 pm
Contact:

string map question

Post by droolin »

When looking through these threads, I seen where a suggestion was made to use string map instead of regsub, which seemed to fit a situation that I am trying to code for. But, for some reason I am having problems with this.

I am trying to use a variable for the replacement value, and the variable name is what is actually being replaced.

"

Code: Select all

:\0038,12 Welcome To ~~~~~~~~,  Our current DJ is ^^^^^^^^ \xab\xa7\xbb:\0038,1 The AweRockRadio  Team \xab\xa7\xbb"

 set lcl_new_msg1 [string map -nocase {~~~~~~~~ $chan ^^^^^^^^ $gbl_DJ_Current_Nick} $gbl_ary_text(OnJoinMsg1)]
And this is what appears.

-
ozzy- Welcome To $chan, Our current DJ is $gbl_DJ_Current_Nick «§»: The AweRockRadio Team «§»
Any suggestions as to what I am doing wrong here?

Any and all help appreciated.

Dan
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

string map wont recognize variables within its map like that. I don't really see why you'd need it tho, when you can just do


set lcl_new_msg1 ":\0038,12 Welcome To $chan, Our current DJ is $gbl_DJ_Current_Nick \xab\xa7\xbb:\0038,1 The AweRockRadio Team \xab\xa7\xbb "

or whatever..That assumes $chan and $gbl_DJ_Current_Nick were previously defined of course.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

The braces prevent variable substitution. Use list to create your map...

Code: Select all

string map [list ~~~ $x ^^^ $y ... $z] $msg
Have you ever read "The Manual"?
Post Reply