如何在VS2008中转换csv文件转换 [英] How to convert csv file conversion in VS2008

查看:236
本文介绍了如何在VS2008中转换csv文件转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我将CSV文件用于我的一个项目,其中包含日语,中文,英语和西班牙语。但是如果我在我的项目中使用该文件,即使我的项目是unicode,它也会读取缓冲区值。



我尝试了什么:



Actually, I use CSV file for one of my projects which contains Japanese,Chinese,English and Spanish languages. But if I use that file in my project, it read buffer values even if my project is in unicode.

What I have tried:

I used ini file to read those languages which works fine but only for unicode. As far as multi-byte is concerned only English and Spanish are read correctly.

推荐答案

以下所有内容都假定您的应用程序是Unicode版本。



看起来您从 CStdioFile 派生了 CSVFile 类。然后 ReadString()将使用运行应用程序的用户的实际选定代码页将多字节文件内容转换为宽字符。当使用不同的编码创建CSV文件时,这将导致错误的结果。



主要问题是知道用于创建的编码/代码页CSV文件。如果您对此有所控制,我建议尽可能使用UTF-8。



一旦知道代码页,请将文件内容读入 char buffer(例如使用 fgets())并调用 MultiByteToWideChar函数(Windows) [ ^ ]转换为Unicode。
All the follwing assumes that your application is a Unicode build.

It looks like you have derived your CSVFile class from CStdioFile. Then ReadString() will convert multi byte file content to wide char using the actually selected code page of the user running your application. That will lead to wrong results when the CSV file has been created with a different encoding.

The main problem is to know which encoding / code page has been used to create the CSV file. If you have control on that, I suggest to use UTF-8 if possible.

Once you know the code page, read the file content into a char buffer (e.g. using fgets()) and call the MultiByteToWideChar function (Windows)[^] to convert to Unicode.


这篇关于如何在VS2008中转换csv文件转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆