如何将8位字符转换为7位字符? (即Ü到U) [英] How do I translate 8bit characters into 7bit characters? (i.e. Ü to U)

查看:148
本文介绍了如何将8位字符转换为7位字符? (即Ü到U)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找将更高位的ascii字符(例如Ü,扩展为ascii 154)转换为U(即ascii 85)的伪代码或示例代码.

I'm looking for pseudocode, or sample code, to convert higher bit ascii characters (like, Ü which is extended ascii 154) into U (which is ascii 85).

我最初的猜测是,由于只有大约25个ascii字符与7位ascii字符相似,因此必须使用转换数组.

My initial guess is that since there are only about 25 ascii characters that are similar to 7bit ascii characters, a translation array would have to be used.

让我知道您是否还能想到其他事情.

Let me know if you can think of anything else.

推荐答案

实际上是unexist提出的: "iconv"功能可以为您处理所有怪异的转换,几乎所有编程语言都提供该功能,并且具有一个特殊选项,可尝试近似转换目标集中缺少的字符.

Indeed as proposed by unexist : "iconv" function exists to handle all weird conversion for you, is available in almost all programming language and has a special option which tries to convert characters missing in the target set with approximations.

使用iconv可以简单地将输入的UTF-8字符串转换为7位ASCII.

Use iconv to simply convert your input UTF-8 string to 7bit ASCII.

否则,您将总是遇到麻烦:使用不同代码页的8位输入使用不同的字符集(因此根本无法与转换表一起使用),却忘记映射最后一个愚蠢的带重音符号的字符(您已映射所有重音/重音,但忘记绘制捷克卡通或北欧的°"),等等.

Otherwise, you'll always end hitting corner case : a 8bit input using a different codepage with a different set of characters (thus not working at all with your conversion table), forgot to map one last stupid accented caracter (you mapped all grave/acute accent, but forgot to map Czech caron or the nordic '°'), etc.

当然,如果您想将解决方案应用于特定的小问题(为音乐收藏创建文件系统友好的文件名),则查找数组是必经之路(可以是上面每个代码编号的数组) 128映射了JeeBee提出的128以下的近似值,或vIceBerg提出的源/目标对,这取决于您选择的语言中已经提供了哪些替换功能),因为它会很快被黑在一起并迅速检查丢失的元素.

Of course if you want to apply the solution to a small specific problem (making file-system friendly filenames for your music collection) the the look-up arrays are the way to go (either an array which for each code number above 128 maps an approximation under 128 as proposed by JeeBee, or the source/target pairs proposed by vIceBerg depending on which substitution functions are already available in your language of choice), because it's quickly hacked together and quickly check for missing elements.

这篇关于如何将8位字符转换为7位字符? (即Ü到U)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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