So, I've been searching for the way to do it and I just can't find it. I'm sure I am missing something trivial.
I'm reading a binary a file where characters are encoded in ANSI (8 bit characters). I want to show their content in a wxString.
For exemple, I read the letter "é":
- fread gives me a char, the letter "é" value is -63 because it is an signed type.
- I cannot use this character directly inside a wxString, it is not valid because it is a character encoded on 8 bit. wxString is empty.
Is there a simple way to do it? Do I need to convert all the time to an of wchar_t first than use that instead?
I'd like to know how you people manage this.
Thx again, sorry if I'm missing something trivial.
How do you read a ANSI encoded files and use it with wxString? Topic is solved
Re: How do you read a ANSI encoded files and use it with wxString?
First of all: Unless it's UTF-8 there is no easy way to reliably detect an 8 bit text encoding. Assuming you know the file is ISO8859-1 encoded:
wxConvISO8859_1 is one of the stock conversion objects, there are also a few others:
https://docs.wxwidgets.org/trunk/overvi ... nv_classes
You can use them also when using the respective wxString contructor:
https://docs.wxwidgets.org/trunk/classw ... 4651d98123
Code: Select all
wxFile f_in( "d:\\some_file.txt" );
wxString s;
f_in.ReadAll( &s, wxConvISO8859_1);
f_in.Close();
wxLogMessage("%s", s);
https://docs.wxwidgets.org/trunk/overvi ... nv_classes
You can use them also when using the respective wxString contructor:
https://docs.wxwidgets.org/trunk/classw ... 4651d98123
Use the source, Luke!
Re: How do you read a ANSI encoded files and use it with wxString?
Code: Select all
wxString name = wxString(n.c_str(), wxConvISO8859_1);