如何在c ++中将utf-8转换为ASCII? [英] how to convert utf-8 to ASCII in c++?

查看:1147
本文介绍了如何在c ++中将utf-8转换为ASCII?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从utf-8的服务器得到响应,但不能读取。
如何在c ++中将utf-8转换为ASCII?

i am getting response from server in utf-8 but not able to read that. how to convert utf-8 to ASCII in c++?

推荐答案

首先注意,ASCII是一个7位格式。有8位编码,如果你是在这些之一(如ISO 8859-1),你需要更具体。

First note that ASCII is a 7-bit format. There are 8-bit encodings, if you are after one of these (such as ISO 8859-1) you'll need to be more specific.

要转换ASCII string to UTF-8,do nothing:they are same。因此,如果您的UTF-8字符串仅由的ASCII字符组成,那么它已经是一个ASCII字符串,不需要转换。

To convert an ASCII string to UTF-8, do nothing: they are the same. So if your UTF-8 string is composed only of ASCII characters, then it is already an ASCII string, and no conversion is necessary.

如果UTF-8字符串包含非ASCII字符(带重音符或非拉丁字符的任何字符),则无法将其转换为ASCII。 (您也许可以将其转换为ISO编码之一)。

If the UTF-8 string contains non-ASCII characters (anything with accents or non-Latin characters), there is no way to convert it to ASCII. (You may be able to convert it to one of the ISO encodings perhaps.)

有些方法可以从拉丁字符中去除重音符,以获得至少一些类似ASCII 。或者,如果您只想删除非ASCII字符,只需从utf-8字符串中删除值> = 128的所有字节。

There are ways to strip the accents from Latin characters to get at least some resemblance in ASCII. Alternatively if you just want to delete the non-ASCII characters, simply delete all bytes with values >= 128 from the utf-8 string.

这篇关于如何在c ++中将utf-8转换为ASCII?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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