当前位置:网站首页>Unicode文件解析方法及存在问题
Unicode文件解析方法及存在问题
2022-07-26 13:11:00 【xiongpursuit88】
问题背景
在项目中遇到需要将一个Unicode编码(UTF-16 LE)的文件内容解析出来,但是在使用MFC的类CStdioFile进行文件读取的时候,出现乱码。
同时,读取的文件有可能还是ASCII编码的,使用CStdioFile读取是可以正常读取。需要同时兼容两个编码。
问题分析
1、Unicode编码的文件其文件前两个字节是0xEF FF,可以以此来判定文件编码格式。
2、将文件以字节流的方式读取出来后,使用MultiBytesToWideChar可以转换成可见字符串。
解决方案
1、既然CStdioFile可以处理ASCII编码,那么可以派生一个类CMyStdioFile专门用于处理Unicode编码。即:CStdioFile处理ASCII编码,CMyStdioFile处理Unicode编码。
2、在打开文件的时候顺便将文件编码判定出来,保存在类成员中,后面使用
代码
#pragma once
边栏推荐
- [typescript] typescript common types (Part 2)
- 【上位机教程】CANopen通信下一体化步进电机与台达PLC(AS228T)的应用
- C#把Type当做泛型T,来作为方法的泛型进行使用
- 学习pinia 介绍-State-Getters-Actions-Plugins
- pomerium
- Use positioning to realize left, middle and right layout, and the middle content is adaptive
- V01 - XX, record a good life from the log
- Outline design specification
- Can I take your subdomain? Exploring Same-Site Attacks in the Modern Web
- Kubernetes APIServer 限流策略
猜你喜欢

1312_ Apply 7z command for compression and decompression

(int argc, char** argv) command line parameters in visual stdio (VS)

Kubernetes flannel: host-gw mode

Shutter background graying effect, how transparency, gray mask

Learn about Pinia state getters actions plugins

HCIP第十一天比较(BGP的配置、发布)

Niuke brush sql---2

After being fined "paid leave" for one month, Google fired him who "loves" AI

【TypeScript】TypeScript常用类型(下篇)

V00 - do whatever you want when you are old
随机推荐
Niuke brush sql---2
Dimension disaster dimension disaster suspense
如何面对科技性失业?
0 basic programming resources (collect first ~ read slowly ~)
Student examination system based on C #
MySQL data directory (2) -- table data structure (XXV)
Elementary notes of binary tree
V00 - do whatever you want when you are old
基于C#开放式TCP通信建立与西门子PLC的socket通信示例
Interviewer: how to understand QPS, TPS, RT?
Some practical operations of vector
【TypeScript】TypeScript常用类型(上篇)
基于Bézier曲线的三维造型与渲染
Display inline+calc realizes left, middle and right layout, and the middle is adaptive
被罚“带薪休假”一个月后,谷歌解雇了“爱”上 AI 的他
jvm:类加载子系统干什么的?由什么组成?需要记住哪些八股文?
Guys, how can CDC Oracle set the reading from the specified SCN number, or how to set the read-only full archive, not to read fast
0基础编程资源大全(先收藏~慢慢看~)
pomerium
Leetcode 2119. number reversed twice