Page 1 of 1

Text File Encoding ANSI to UTF-8

Posted: 09 Oct 2018 08:49
by Nel
How to change the Text File Encoding?

Re: Text File Encoding ANSI to UTF-8

Posted: 09 Oct 2018 12:18
by ShadowThief
The easiest way (short of opening the file with a text editor and saving it manually) is probably with ConvertCP.exe. Beyond that, my next thought would be to add the UTF-8 BOM to the front of the text file, but that might not be the best solution for some circumstances.

Re: Text File Encoding ANSI to UTF-8

Posted: 09 Oct 2018 14:56
by dbenham
I agree, aGerman's ConvertCP.exe utility would be an ideal solution. You want to translate to code page 65001. Add the /B option if you want a BOM in your output.

Alternatively, you could use my JREPL.BAT utility. It is designed to do regular expression find/replace operations on text files, but it has the ability to read and write different encodings.

The following assumes the "ANSI" source encoding matches the default encoding used by your machine:

Code: Select all

call jrepl "$^" "" /f "input.txt" /o "output.txt|utf-8"
The above will terminate every line with carriage return linefeed (\r\n), regardless how the source lines were terminated. If you want to preserve the original line terminators, then add the /M option.

By default the output will include the BOM. If you don't want a BOM, then use /O "output.txt|utf-8|nb".

If the ANSI encoding does not match your machines default, then you will have to specify the encoding within the /I option. For example, if your encoding is Central/Eastern European code page 1250, then

Code: Select all

call jrepl "$^" "" /f "input.txt|windows-1250" /o "output.txt|utf-8"

Re: Text File Encoding ANSI to UTF-8

Posted: 10 Oct 2018 01:30
by Nel
Thanks.