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.

Delete some characters

Help for those learning Tcl or writing their own scripts.
Post Reply
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Delete some characters

Post by darton »

Hello!
I have a script that stores some names in a textfile. Is it possible that special characters will be deleted before it is stored in the file?
For example my bot should save this name: "-{SFR}-Nick" but it should delete the "{" and "}" so that in the textfile there is only "-SFR-Nick".
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

set nick [string map {\{ "" \} ""} $nick]
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

OK, thank you, it works, but there is a problem. If there are numbers in the name, my bot does not delete the "{" and the "}". For example: if the nick is "-{SFR}-Nick123", my bot should save this nick in this way: "-SFR-Nick123", but it does not delete the "{" and the "}". This problem only appears if there are numbers in the name. Can anyone help me?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Tclsh8.4:
% set foo -{SFR}-Nick123
-{SFR}-Nick123
% set foo [string map {\{ "" \} ""} $foo]
-SFR-Nick123
%
d
darton
Op
Posts: 155
Joined: Sat Jan 21, 2006 11:03 am

Post by darton »

OK, I made a mistake. In the nick I used there were other escape characters like "[" and "]". I deleted them with string map, too, because otherwise the "{" and the "}" would not be deleted.
Post Reply