Reputation: 5
I am having troubles reading special characters in vbs script. My reading file goes like this.
ls_folder = "file path"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fa = fso.OpenTextFile(ls_folder + f1.Name, 1, False)
Do While fa.AtEndOfStream <> True
Line = fa.readline
'Code
Next
If I open files with N++ I get that encoding is ANSI. I tried using 4th parameter for OpenTextFile but none of 3 values have worked for me. Script doesnt read "ł" character. When encoded to ascii it gives value 179.
Is there any other way to declare encoding other than using ADODB.Stream, which allows to declare Charset.
Upvotes: 0
Views: 2339
Reputation: 30113
Use AscW
function rather than Asc
one: AscW is provided for 32-bit platforms that use Unicode characters. It returns the Unicode (wide) character code, thereby avoiding the conversion from Unicode to ANSI
.
Note that "ł
" character (Unicode U+0142
i.e. decimal 322
) is defined in next ANSI
code pages:
Asc("ł")
returns 179
in ANSI 1250
Central Europe andAsc("ł")
returns 249
in ANSI 1257
Baltic.For proof, open charmap.exe
or run my Alt KeyCode Finder script:
==> mycharmap "ł"
Ch Unicode Alt? CP IME Alt Alt0 IME 0405/cs-CZ; CP852; ANSI 1250
ł U+0142 322 …66… Latin Small Letter L With Stroke
136 CP852 cs-CZ 136 0179 (ANSI 1250) Central Europe
136 CP775 et-EE 0249 (ANSI 1257) Baltic
ł
==>
For the sake of completeness, AscB("ł")
returns 66
…
Upvotes: 1
Reputation: 958
Add another argument to OpenTextFile to specify 'Unicode'. After the 'False' value which says "don't create the file" add 1 as extra argument.
Upvotes: 0