[新手求教]字符编码问题

这是wxWidgets论坛的中文版本。在这里,您可以用您的母语汉语讨论上面任一子论坛所涉及的所有关于wxWidgets的话题。欢迎大家参与到对有价值的帖子的中英互译工作中来!
Post Reply
supervila
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Nov 18, 2008 8:35 am

[新手求教]字符编码问题

Post by supervila » Tue Nov 18, 2008 8:46 am

现在从GB180380编码的文件中读取一个字符串到char数组中,现在我想把它的内容显示到一个控件中,显示为乱码,请问该如何转换?

supervila
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Nov 18, 2008 8:35 am

Post by supervila » Wed Nov 19, 2008 2:28 am

我查了下,问题在我读文件的地方,我用wxTextFile读的,第二个参数给的是wxConvFile.

我跟踪了一下,发现读出数据的时候中文就已经不对了。是不是wxTextFile类只能读取UTF—8编码的文件?

spritez
Earned a small fee
Earned a small fee
Posts: 21
Joined: Sat Apr 19, 2008 2:16 pm
Location: china

Post by spritez » Mon Dec 08, 2008 6:14 am

字符编码问题经常搅得我也很头痛,你说的问题我没应用过,建议你查看一下wx.chm中Topic overviews下的wxString overview和wxMBConv classes overview主题,特别是后一个。当然我个人认为,WX可能只能处理Unicode字串,正确的转换是必不可少的。

摘抄:
Converting strings
Once you have chosen which object you want to use to convert your text, here is how you would use them with wxString. These examples all assume that you are using a Unicode build of wxWidgets, although they will still compile in a non-Unicode build (they just won't convert anything).

Example 1: Constructing a wxString from input in current encoding.


wxString str(input_data, *wxConvCurrent);

Example 2: Input in UTF-8 encoding.

wxString str(input_data, wxConvUTF8);

Example 3: Input in KOI8-R. Construction of wxCSConv instance on the fly.

wxString str(input_data, wxCSConv(wxT("koi8-r")));
*** china ***

Post Reply