(This is all on El Capitan in case this is a Mac-specific issue.)
I tried building an old app in 64-bit and immediately ran into issues which I eventually narrowed down to some bad characters being read in from a text file. So I came up with a little test to see what’s going on. I have a text file containing the following:
Id
Ill
Im
Ive
BBEdit tells me this is a UTF-8 file. I read the contents of the file, split it on endofline and then turn around and write out each member of the array to another text file. My code:
[code] dim f as FolderItem
dim t as TextInputStream
dim o as TextOutputStream
dim s, x() as string
dim i as integer
f = SpecialFolder.Desktop.Child(“test_input.txt”)
t = TextInputStream.Open(f)
t.Encoding = Encodings.utf8
s = t.ReadAll
t.Close
s = ReplaceLineEndings(s, endofline)
s = trim(s)
f = SpecialFolder.Desktop.Child(“test_output.txt”)
if not f.Exists then
o = TextOutputStream.Create(f)
else
o = TextOutputStream.Append(f)
end if
x = s.Split(EndOfLine)
for i = 0 to x.Ubound
#If Target32Bit then
o.Write("32-bit: " + x(i) + EndOfLine)
#elseif Target64Bit then
o.Write("64-bit: " + x(i) + EndOfLine)
#endif
next
o.Close()
[/code]
If I run this in 32-bit, I get a file (which BBEdit says is UTF-8) with the following as expected:
32-bit: Id
32-bit: Ill
32-bit: Im
32-bit: Ive
If I switch to 64-bit, build it and run the app I now get this in the file, which BBEdit now says has become Western (Mac OS Roman).
32-bit: IÄôd
32-bit: IÄôll
32-bit: IÄôm
32-bit: IÄôve
64-bit: IÄ
64-bit: d
I
64-bit: ôll
64-bit: IÄôm
IÄôve
I tried changing the 64-bit write line to:
o.Write(ConvertEncoding("64-bit: " + x(i) + EndOfLine, Encodings.UTF8))
But get the same results. Is this a known issue, new bug, or am I handling the encoding wrong?