比较C ++中的中文字符串 [英] Comparing Chinese Strings in C++

查看:108
本文介绍了比较C ++中的中文字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在跨平台开发,通过该平台我可以将基于UTF-8的消息数据(包含汉字)从Windows发送到Linux.

现在在Linux端(使用C ++),我需要比较每行以找到我正在寻找的中文字符串,并根据是否找到中文字符串进行处理.

问题是,即使我可以看到Im在Linux端读取的消息中也存在中文字符串,但比较找不到它.我正在使用std :: wstring并使用wstring的find()方法.

当我在Linux中将消息打印到标准输出(控制台)时,我可以看到中文字符串,但是find找不到它.在Linux方面,我为中文字符串添加了"L"前缀,即L< chinese string =">.

非常感谢您提供任何帮助,帮助您弄清为什么即使存在中文字符串也找不到它.

THanks

Hi,

Im working on a cross plateform development whereby Im sending a UTF-8 based message data (containing Chinese characters) from Windows to Linux.

Now on the Linux side (using C++), I need to compare each line to find the Chinese string Im looking for and do the processing based on if I find the Chinese strings.

The question is that even though I can see the Chinese string exist in the message that Im reading on the Linux side, the comparison is not finding it. Im using std::wstring and using the find() method of the wstring.

When I print the message to the standard output (console) in Linux, I can see the Chinese string, but find is not finding it. In the Linux side, I am prefixing the Chinese string with "L" i.e. L "<chinese string="">".

Will appreciate any help in figuring out why the Chinese string is not being found even though it exists.

THanks

推荐答案

这是一个很棒的项目:
ICU-Unicode的国际组件 [ ^ ],它将在Windows和Linux上完成这项工作.

问候
Espen Harlinn
This is a great project:
ICU - International Components for Unicode[^], it will do the job on windows and linux.

Regards
Espen Harlinn


这篇关于比较C ++中的中文字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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