Download MetaTrader 5

open a file: read|bin & UTF8?

To add comments, please log in or register
Carl Schreiber
Carl Schreiber 2016.05.29 19:21 


we heard mt4 is now UTF8.

So I have a file save as a utf-8 file from Notepad++. Its first line in Notepad++, in Windows' Editor and Word Pad begins with

Sugar; ...

BUT if I open it like this:

   int nL,hdl  = FileOpen("Para.csv",FILE_READ|FILE_SHARE_READ|FILE_BIN|FILE_COMMON);
   if (hdl == INVALID_HANDLE) { Alert("Can't read Para.csv in ..\\Terminal\\Common\\Files: ",_LastError); FileClose(hdl); return; }
   string allLines[], f = FileReadString(hdl,(int)FileSize(hdl));
   nL = StringSplit(f,StringGetCharacter("\n",0),allLines); // u_sep=StringGetCharacter("\n",0); 
   lSz = ArraySize(allLines);

I see that now the 1st line starts with:

Sugar; ...

As this looks pretty much like an ANS-ASCII-UTF-8 missmatch saved it as from Notepad++ as ANSI and I don't have the problem, the first line start with

Sugar; ...

1) I thought mt4 is on UTF8 - ???

2) How do I open a bin File in UTF8?

If I try:

FileOpen("PipFind.csv",FILE_READ|FILE_SHARE_READ|FILE_BIN|FILE_COMMON, CP_UTF8); // no change as before CP_UTF8 has to be set a delimiter

no change as before CP_UTF8 has to be set a delimiter, so I tried:


But now the first Line begins with:

¿Sugar; ...

Not really what I want and what I need.

Does anybody know how do I open files to read and to write in bin-mode and UTF-8?

whroeder1 2016.05.29 21:07  


we heard mt4 is now UTF8.

2) How do I open a bin File in UTF8?
   string allLines[], f = FileReadString(hdl,(int)FileSize(hdl));
  1. Since February 3, 2014 (Build 600) Strings are Unicode What's New in MQL4 - MQL4 Documentation Upgrade to MetaTrader 4 Build 600 and Higher - MQL4 Articles
  2. If you read the documentation FileOpen - File Functions - MQL4 Reference
    FILE_BIN binary read-write mode (no conversion from a string and to a string)
    You would know. There is no UTF8/UTF16 in binary files. You must convert the characters yourself CharArrayToString - Conversion Functions - MQL4 Reference
  3. Alternatively if there is only character data, open the file as ANSI.

Carl Schreiber
Carl Schreiber 2016.05.30 06:57  


I gave up using (reading, writing) UFT-8 files.

It reminds me of the problem I had to sign a powershell script - the script has to loaded and saved (by e.g. Notepad++) as ANSI otherwise it isn't working!

To add comments, please log in or register