- 论坛徽章:
- 0
|
long1280 网友使用g_convert(srcStr,-1,"UTF-8","GB2312",NULL,NULL,NULL)解决了网络程序中,gtk界面显示windows传过来的中文信息的问题.从DevHelp里查到了g_convert函数的声明:
- gchar* g_convert (const gchar *str,
- gssize len,
- const gchar *to_codeset,
- const gchar *from_codeset,
- gsize *bytes_read,
- gsize *bytes_written,
- GError **error);
- Converts a string from one character set to another.
- Note that you should use g_iconv() for streaming conversions[2].
- str : the string to convert
- len : the length of the string, or -1 if the string is nul-terminated[1].
- to_codeset : name of character set into which to convert str
- from_codeset : character set of str.
- bytes_read : location to store the number of bytes in the input string that were successfully converted, or NULL. Even if the conversion was successful, this may be less than len if there were partial characters at the end of the input. If the error G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value stored will the byte offset after the last valid input sequence.
- bytes_written : the number of bytes stored in the output buffer (not including the terminating nul).
- error : location to store the error occuring, or NULL to ignore errors. Any of the errors in GConvertError may occur.
- Returns : If the conversion was successful, a newly allocated nul-terminated string, which must be freed with g_free(). Otherwise NULL and error will be set.
复制代码
看样子long1280网友是将windows传过来的字符串从gb2312转换成UTF-8才正常显示到了GTK控件上.
推理:我应该把从GTK控件获取到的中文字符串从UTF-8转化成gb2312才能正常显示到windows程序里.
由此我联想到我挂载windows分区时的mount参数:
mount -t ntfs -o iocharset=gb2312 /dev/hda* /mnt/D
iocharset=gb2312指定字符集为gb2312,这样挂过来的windows分区中文文件名才不会出现乱码.可我收集到的资料显示Windows 2000及 XP均使用了Unicode,在这里我有一些不解.中文版的Windows使用gb2312吗?
现在在家里,只有一台机器,没办法测试,明天上班的时候试试g_convert(srcStr,-1,"GB2312","UTF-8",NULL,NULL,NULL)把GTK控件的字符串从UTF-8转换成GB2312发送到A机器的Windows版的程序看看可行性如何.
[ 本帖最后由 hunbuso 于 2007-4-3 20:42 编辑 ] |
评分
-
查看全部评分
|