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 ?
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
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.