Force a file to be read as UTF-8?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
boiler
Posts: 3914
Joined: 21 Dec 2014, 02:44

Force a file to be read as UTF-8?

01 Feb 2015, 00:47

I have a file that has characters that will only be interpreted correctly if the file is read as UTF-8 (characters such as ü). However, it doesn't have the UTF-8 BOM byte header of 0xEF,0xBB,0xBF. The file is created by another program (via PostgreSQL queries requested by my script). When I read the lines from this file, the script doesn't recognize the extended characters correctly, but I have seen that they will be read correctly if the file has the UTF-8 BOM header.

So my question is: Is there a way to force my script to read a file as a UTF-8 file even if it doesn't have the UTF-8 BOM? That would allow me to avoid having to read the file contents and write them back out to a new file with the UTF-8 BOM. I would have to do this for each query that could potentially have these characters in them. Or is that really the only way to do it? It would just be better for performance to limit how much I'm reading and writing files if I could avoid that.
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Re: Force a file to be read as UTF-8?

01 Feb 2015, 00:56

Untested, f := FileOpen(file, "rw", "UTF-8"). See: FileOpen
User avatar
boiler
Posts: 3914
Joined: 21 Dec 2014, 02:44

Re: Force a file to be read as UTF-8?

01 Feb 2015, 01:06

Thanks. I'll try that.

Return to “Ask For Help”

Who is online

Users browsing this forum: akaza_dorian, Bing [Bot], Google [Bot], SashaChernykh, Scr1pter and 413 guests