在C ++中将宽字符串转换为小写 [英] Converting wide char string to lowercase in C++

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

问题描述

如何在C ++中将wchar_t字符串从大写转换为小写?

How do I convert a wchar_t string from upper case to lower case in C++?

字符串包含日语,中文,德语和希腊字符。

The string contains a mixture of Japanese, Chinese, German and Greek characters.

我想过使用towlower ...

I thought about using towlower...

http://msdn.microsoft.com/zh-CN/library/8h19t214%28VS.80%29.aspx

。但文档说明:


下拉菜单的情况转换是特定于区域设置的。只有与当前语言环境相关的字符才会更改。

The case conversion of towlower is locale-specific. Only the characters relevant to the current locale are changed in case.

编辑:也许我应该描述我在做什么。我收到来自用户的Unicode搜索查询。它最初是以UTF-8编码,但我将它转换为widechar(我可能在字面上错了)。我的调试器(VS2008)正确显示日语,德语等字符在变量快速观察。我需要经历另一组数据的Unicode和查找匹配的搜索字符串。虽然这不是我的问题,当搜索区分大小写,它是更麻烦的做它不区分大小写。我的(可能天真的)解决问题的方法是将所有输入数据和输出数据转换为小写,然后比较。

Maybe I should describe what I'm doing. I receive a Unicode search query from a user. It's originally in UTF-8 encoding, but I'm converting it to a widechar (I may be wrong on the wording). My debugger (VS2008) correctly shows the Japanese, German, etc characters in in the "variable quick watch". I need to go through another set of data in Unicode and find matches of the search string. While this is no problem for me to do when the search is case sensitive, it's more problematic to do it case insensitive. My (maybe naive) approach to solve the problem would be to convert all input data and output data to lower case and then compare it.

推荐答案

如果您的字符串包含所有这些字符,则代码集必须基于Unicode。如果正确实施, Unicode (第4章'字符属性')定义字符属性,包括字符是大写还是小写映射,等等。

If your string contains all those characters, the codeset must be Unicode-based. If implemented properly, Unicode (Chapter 4 'Character Properties') defines character properties including whether the character is upper case and the lower case mapping, and so on.

鉴于前导,< wctype.h> towlower()函数是正确的工具使用。如果它没有做这项工作,你有一个QoI(实施质量)问题与供应商讨论。如果你发现供应商没有反应,那么看看替代库。在这种情况下,您可以考虑 ICU (Unicode的国际组件)。

Given that preamble, the towlower() function from <wctype.h> is the correct tool to use. If it doesn't do the job, you have a QoI (Quality of Implementation) problem to discuss with your vendor. If you find the vendor unresponsive, then look at alternative libraries. In this case, you might consider ICU (International Components for Unicode).

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

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