在 C++ 中转换字符编码 [英] Converting character encoding within c++

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

问题描述

我有一个允许用户输入用户名的网站.

I have a website which allows users to input usernames.

这里的问题是 c++ 中的代码假设浏览器编码是西欧,并将从用户名文本框中收到的字符串转换为 unicode 以与存储在数据库中的字符串进行比较.

The problem here is that the code in c++ assumes the browser encoding is Western Europe and converts the string received from the username text box into unicode to compare with string stored within the databasse.

使用正确的浏览器编码设置字符 úser 被接收为 %FAser 并在程序中正确地转换为 úser然而,在浏览器设置为 UTF-8 的情况下,字符串被接收为 %C3%BAser,然后由于代码将 C3 和 BA 转换为单独的字符而转换为 úser.

with the right browser encoding set the character úser is recieved as %FAser and coverted properly to úser within the program however with the browser settings set to UTF-8 the string is recieved as %C3%BAser and then converted to úser due to the code converting C3 and BA as seperate characters.

有没有办法将示例 %c3%BA 转换为 ú,同时确保进行正确的转换?

Is there a way to convert the example %c3%BA to ú while ensuring the right conversions are being made?

推荐答案

您可以使用 ICU 库来转换在几乎所有可用的编码之间.这个库还提供了很多字符串操作工具.

You can use the ICU library to convert between almost all usable encodings. This library also provides lots of string manipulation facilities.

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

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