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.

How to combine several string map functions in one?

Old posts that have not been replied to for several years.
Locked
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

How to combine several string map functions in one?

Post by awyeah »

I would like to know how to perform multiple, string map functions in one line. This function: (to reduce)

Code: Select all

[string map {"]" "\]"} $nick] + [string map {"[" "\["} $nick] + [string map {"{" "\{"} $nick] + [string map {"}" "\}"} $nick] + [string map {"\" "\\" $nick]
Basically I want to escape all the special characters in a nick. I know how todo it with regsub, but I want to use string map as it is faster. :mrgreen:
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: How to combine several string map functions in one?

Post by user »

Have you ever read "The Manual"?
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

So it will be like this, I guess.

Code: Select all

set nick [string map {[ \[ ] \] { \{ } \} \ \\} $nick] 
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

awyeah wrote:So it will be like this, I guess.

Code: Select all

set nick [string map {[ \[ ] \] { \{ } \} \ \\} $nick]
Yes and no. I can't believe you don't know how braces work after all this time scripting tcl. Read http://tcl.tk/man/tcl8.5/TclCmd/Tcl.htm#M10

{[ \\[ ] \\] \{ \\\{ \} \\\} \\ \\\\}
Have you ever read "The Manual"?
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

LOL thanx. Yes we need to add one blackslash to the original one and two backslashes to the one to replace the original one with.

*/me* shunts, have had alot of coffee.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Well, it seems to work only for one char. If there are two or more same chars, then I get an error of invoked.

I think 'regsub -all' will be a better idea, thanx anyway.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

awyeah wrote:Well, it seems to work only for one char. If there are two or more same chars, then I get an error of invoked.
What error do you get? It works just fine for me.
Have you ever read "The Manual"?
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Well, I bind join and used it in my script.
Nick: Sa]ma... no error

Then I changed to the nick:
Nick: Sa][ma.... error

Tcl error, invoked from within
'missing close bracket' or something like that.

I am trying to use $nick in a variable a global array join_part($nick).

I saw it always gives errors if two characters or more are present, not if one is present,

join_part([TesTeR]) --> gives and error
join_part([TesTeR) --> doesn't given an error
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

And why would you need to manually escape chars in the element name? The error is not caused by the string map, but by something else you're doing.
Have you ever read "The Manual"?
Locked