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.

Problem with special characters ² ³ and °

Help for those learning Tcl or writing their own scripts.
t
tomcat
Voice
Posts: 7
Joined: Thu Dec 11, 2008 4:57 am

Problem with special characters ² ³ and °

Post by tomcat »

Hi i have some problems with ² ³ and ° i want to replace them with \² \³ and \° but for example
regsub -all -- \\\³ $data \\\³ data does not work :(
some guys told me to use
regsub -all -- {(\\|\[|\]|\&|\{|\}|"|'|\262|\263)} $data {\\\1} data
to remove all special characters. It works fine with []{}&\'" but not with ², ³ or °
Can anyone help me and tell me what to do to get what i need ?
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

did u try?

Code: Select all

regsub -all "°" $data "" data
t
tomcat
Voice
Posts: 7
Joined: Thu Dec 11, 2008 4:57 am

Post by tomcat »

does not work
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Make sure your script has the right encoding (check '.tcl encoding system'), or, if you're using Tcl >= 8.5, use the -encoding option when loading the script.
tomcat wrote:regsub -all -- \\\³ $data \\\³ data does not work :(
Are you sure? :lol: It probably works, but you're replacing "\³" with "\³", so it is kind of hard to spot the difference :)
Have you ever read "The Manual"?
t
tomcat
Voice
Posts: 7
Joined: Thu Dec 11, 2008 4:57 am

Post by tomcat »

proc filt {data} {
regsub -all -- {(\\|\[|\]|\&|\{|\}|"|'|\262|\263)} $data {\\\1} data
return $data

or

proc filt {data} {
regsub -all -- {(\\|\[|\]|\&|\{|\}|"|'|\²|\³)} $data {\\\1} data
return $data

does not work -.-

Its an eggdrop script how to use the -encoding option ?
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

tomcat wrote:how to use the -encoding option ?
source -encoding <encoding used in your script> script.tcl
Have you ever read "The Manual"?
t
tomcat
Voice
Posts: 7
Joined: Thu Dec 11, 2008 4:57 am

Post by tomcat »

source -encoding iso-8659-1 scripts/scanner.tcl
results in crash...
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

tomcat wrote:source -encoding iso-8659-1 scripts/scanner.tcl
results in crash...
tcl version 8.5.x? because its option from 8.5 :)
t
tomcat
Voice
Posts: 7
Joined: Thu Dec 11, 2008 4:57 am

Post by tomcat »

8.5.5
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

tomcat wrote:8.5.5
try:

Code: Select all

source -encoding iso8859-1 scripts/scanner.tcl
u mean 8859 not 8659? ;p

:>
t
tomcat
Voice
Posts: 7
Joined: Thu Dec 11, 2008 4:57 am

Post by tomcat »

I tried iso 8859 the other is not known and utf-8

it doesnt matter ² ³ ° still dont get replaced with \² \³ \°
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

damn, I have no problem with this char on my bot

u can always try to change this char to its code number, and after that u can delete it from whole string or smth :>

do some trigger and simple IF, !test <special_char> and after in test script if {$arg == "special_char"} { puts "its ok" }

cause we dont know what is current wrong :P
like user wrote, that can be smth with codepage ;]
t
tomcat
Voice
Posts: 7
Joined: Thu Dec 11, 2008 4:57 am

Post by tomcat »

We found a dirty but working way to fix it :)
tnx all for help
User avatar
incith
Master
Posts: 275
Joined: Sat Apr 23, 2005 2:16 am
Location: Canada

Post by incith »

tomcat wrote:We found a dirty but working way to fix it :)
tnx all for help
Thank you for posting your solution.
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

An interesting subject.

I have long suffered the mystical art of fonts, code pages, encodings and the like.

Lets say I copy/paste from the character map tool in windows to build up a text string as follows :-

% set mytest "at xy³ + y² temperature is 14°"
at xy³ + y² temperature is 14°

An attempt to modify (add a backslash to) the special characters using their equivalent hex values and regsub does not work :-

% return [regsub -all -- {[\xB0\xB2\xB3]} $mytest "\\\\&"]
at xy³ + y² temperature is 14°

It should have worked. It seems clear that copy/paste from windows character map does not result in the expected hex characters in the Tcl interpreter I am using.

However, if we explicity use hex character notation to build up the exact same text string as follows :-

% set mytest "at xy\xB3 + y\xB2 temperature is 14\xB0"
at xy³ + y² temperature is 14°

It looks the same, but now using the same regsub statement :-

% return [regsub -all -- {[\xB0\xB2\xB3]} $mytest "\\\\&"]
at xy\³ + y\² temperature is 14\°

It works!

If it is any help to the original poster, if you are able to explicitly build up your string using hex notation then that would enable you to use hex notation in the regsub pattern successfully.

If not, then it remains a mystical art which will eventually result in insanity.
Post Reply