| View previous topic :: View next topic |
| Author |
Message |
tomcat Voice
Joined: 11 Dec 2008 Posts: 7
|
Posted: Thu Dec 11, 2008 5:07 am Post subject: Problem with special characters ² ³ and ° |
|
|
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 ? |
|
| Back to top |
|
 |
tomekk Master

Joined: 28 Nov 2008 Posts: 255 Location: Oswiecim / Poland
|
Posted: Thu Dec 11, 2008 8:43 am Post subject: |
|
|
did u try?
| Code: | | regsub -all "°" $data "" data |
|
|
| Back to top |
|
 |
tomcat Voice
Joined: 11 Dec 2008 Posts: 7
|
Posted: Thu Dec 11, 2008 10:04 am Post subject: |
|
|
| does not work |
|
| Back to top |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Thu Dec 11, 2008 10:26 am Post subject: |
|
|
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? It probably works, but you're replacing "\³" with "\³", so it is kind of hard to spot the difference  _________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
tomcat Voice
Joined: 11 Dec 2008 Posts: 7
|
Posted: Thu Dec 11, 2008 1:47 pm Post subject: |
|
|
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 ? |
|
| Back to top |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Thu Dec 11, 2008 2:13 pm Post subject: |
|
|
| tomcat wrote: | | how to use the -encoding option ? |
source -encoding <encoding used in your script> script.tcl _________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
tomcat Voice
Joined: 11 Dec 2008 Posts: 7
|
Posted: Thu Dec 11, 2008 2:32 pm Post subject: |
|
|
source -encoding iso-8659-1 scripts/scanner.tcl
results in crash... |
|
| Back to top |
|
 |
tomekk Master

Joined: 28 Nov 2008 Posts: 255 Location: Oswiecim / Poland
|
Posted: Thu Dec 11, 2008 3:32 pm Post subject: |
|
|
| tomcat wrote: | source -encoding iso-8659-1 scripts/scanner.tcl
results in crash... |
tcl version 8.5.x? because its option from 8.5  |
|
| Back to top |
|
 |
tomcat Voice
Joined: 11 Dec 2008 Posts: 7
|
Posted: Thu Dec 11, 2008 4:07 pm Post subject: |
|
|
| 8.5.5 |
|
| Back to top |
|
 |
tomekk Master

Joined: 28 Nov 2008 Posts: 255 Location: Oswiecim / Poland
|
Posted: Thu Dec 11, 2008 4:11 pm Post subject: |
|
|
try:
| Code: | | source -encoding iso8859-1 scripts/scanner.tcl |
u mean 8859 not 8659? ;p
:> |
|
| Back to top |
|
 |
tomcat Voice
Joined: 11 Dec 2008 Posts: 7
|
Posted: Thu Dec 11, 2008 4:38 pm Post subject: |
|
|
I tried iso 8859 the other is not known and utf-8
it doesnt matter ² ³ ° still dont get replaced with \² \³ \° |
|
| Back to top |
|
 |
tomekk Master

Joined: 28 Nov 2008 Posts: 255 Location: Oswiecim / Poland
|
Posted: Thu Dec 11, 2008 4:55 pm Post subject: |
|
|
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
like user wrote, that can be smth with codepage ;] |
|
| Back to top |
|
 |
tomcat Voice
Joined: 11 Dec 2008 Posts: 7
|
Posted: Thu Dec 11, 2008 5:13 pm Post subject: |
|
|
We found a dirty but working way to fix it
tnx all for help |
|
| Back to top |
|
 |
incith Master

Joined: 23 Apr 2005 Posts: 275 Location: Canada
|
Posted: Mon Dec 22, 2008 2:00 pm Post subject: |
|
|
| tomcat wrote: | We found a dirty but working way to fix it
tnx all for help |
Thank you for posting your solution. _________________ ; Answer a few unanswered posts! |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Fri Dec 26, 2008 9:37 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
|