dbenham wrote:Thanks Antonio - those unicode maps worked perfectly.
Dave Benham
You are welcome, Dave! I am glad that it was useful to you...
That conversion table was defined via several tests with files created with ADO, that allows to manage both the Ascii and Unicode numbers. However, I was thinking about a method to get the conversion table with no use of ADO, so I devised a brute force method that send each Unicode character from 128 to 65535 to a redirected disk file and then compare the result vs. each one of the 32 problematic Ascii characters in 128-159 range that were previously stored in individual disk files via Batch code.
Code: Select all
@if (@CodeSection == @Batch) @begin
@echo off
setlocal EnableDelayedExpansion
set "AsciiChars128-159=€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"
del AsciiChars*.txt 2> NUL
for /L %%c in (128,1,159) do (
echo !AsciiChars128-159:~0,1!> AsciiChar%%c.txt
set "AsciiChars128-159=!AsciiChars128-159:~1!"
)
del ConversionTable.txt 2> NUL
for /L %%c in (128,1,65535) do (
if not exist AsciiChar*.txt goto break
set /P "=%%c," < NUL
Cscript //nologo //E:JScript "%~F0" %%c > JScriptChar.txt 2> NUL
for %%s in (JScriptChar.txt) do if %%~Zs equ 3 (
set "codeFound="
for %%f in (AsciiChar*.txt) do if not defined codeFound (
fc /B %%f JScriptChar.txt > NUL
if not errorlevel 1 (
set AsciiCode=%%~Nf
set AsciiCode=!AsciiCode:~-3!
echo AsciiCode[!AsciiCode!] = %%c; >> ConversionTable.txt
del %%f
set codeFound=true
echo/
echo Ascii code !AsciiCode! is Unicode character %%c
)
)
)
)
:break
goto :EOF
@end
WScript.Stdout.WriteLine( String.fromCharCode(parseInt(WScript.Arguments.Unnamed.Item(0))) );
I run this program in my computer and got this table:
Code: Select all
AsciiCode[129] = 129;
AsciiCode[141] = 141;
AsciiCode[143] = 143;
AsciiCode[144] = 144;
AsciiCode[157] = 157;
AsciiCode[140] = 338;
AsciiCode[156] = 339;
AsciiCode[138] = 352;
AsciiCode[154] = 353;
AsciiCode[159] = 376;
AsciiCode[142] = 381;
AsciiCode[158] = 382;
AsciiCode[131] = 401;
AsciiCode[136] = 710;
AsciiCode[152] = 732;
AsciiCode[150] = 8211;
AsciiCode[151] = 8212;
AsciiCode[145] = 8216;
AsciiCode[146] = 8217;
AsciiCode[130] = 8218;
AsciiCode[147] = 8220;
AsciiCode[148] = 8221;
AsciiCode[132] = 8222;
AsciiCode[134] = 8224;
AsciiCode[135] = 8225;
AsciiCode[149] = 8226;
AsciiCode[133] = 8230;
AsciiCode[137] = 8240;
AsciiCode[139] = 8249;
AsciiCode[155] = 8250;
AsciiCode[128] = 8364;
AsciiCode[153] = 8482;
Just for completeness, here is another method to achieve the conversion in a simpler way that does not require to first generate the character and then check if it is greather than 255:
Code: Select all
@if (@CodeSection == @Batch) @begin
@echo off
Cscript //nologo //E:JScript "%~F0"
goto :EOF
@end
var i, code, AsciiCode = new Array();
AsciiCode[128] = 8364;
AsciiCode[130] = 8218;
AsciiCode[131] = 401;
AsciiCode[132] = 8222;
AsciiCode[133] = 8230;
AsciiCode[134] = 8224;
AsciiCode[135] = 8225;
AsciiCode[136] = 710;
AsciiCode[137] = 8240;
AsciiCode[138] = 352;
AsciiCode[139] = 8249;
AsciiCode[140] = 338;
AsciiCode[142] = 381;
AsciiCode[145] = 8216;
AsciiCode[146] = 8217;
AsciiCode[147] = 8220;
AsciiCode[148] = 8221;
AsciiCode[149] = 8226;
AsciiCode[150] = 8211;
AsciiCode[151] = 8212;
AsciiCode[152] = 732;
AsciiCode[153] = 8482;
AsciiCode[154] = 353;
AsciiCode[155] = 8250;
AsciiCode[156] = 339;
AsciiCode[158] = 382;
AsciiCode[159] = 376;
for ( i = 0; i <= 255; i++ ) {
code = (AsciiCode[i] != undefined) ? AsciiCode[i] : i;
WScript.Stdout.Write(String.fromCharCode(code));
}
As you indicated, the characters that appear in the screen are different when they are displayed directly by the JScript program vs. any type of Batch code.
Antonio