简体   繁体   English

在ISO-8559-1和cp1251之间转换

[英]Converting between ISO-8559-1 and cp1251

My Android app uses an open-source library that only accepts text data in an ISO-8859-1 encoding. 我的Android应用程序使用的开源库只接受ISO-8859-1编码的文本数据。 I have a few users from Eastern Europe who would like to enter cp1251-encoded text. 我有一些来自东欧的用户想要输入cp1251编码的文本。 This seems to be a limitation of the open-source library, as Java is fully capable of supporting these formats as well as unicode formats. 这似乎是开源库的限制,因为Java完全能够支持这些格式以及unicode格式。

One option could be to modify the open-source library to support multiple character sets. 一种选择是修改开源库以支持多个字符集。 Would it be possible to convert cp1251 to ISO-8859-1 and then back again? 是否可以将cp1251转换为ISO-8859-1然后再转回? Since they are both 8-bit language encodings, it seems like you would be storing the same amount of data at a byte level. 由于它们都是8位语言编码,因此您可能会在字节级别存储相同数量的数据。 However, when the open-source library loads the byte data into a string with ISO-8859-1 encoding, any byte value not present in ISO-8859-1 would likely throw an exception. 但是,当开源库将字节数据加载到具有ISO-8859-1编码的字符串中时,ISO-8859-1中不存在的任何字节值都可能引发异常。

I'm not a character set expert, but the fact that I can't find code samples doing this conversion leads me to believe it won't work, at least not reliably. 我不是一个字符集专家,但是我无法找到进行此转换的代码示例,这让我相信它不会起作用,至少不可靠。

You are correct that this won't work very well at all. 你是对的,这根本不会很好。 Most of the non-ASCII characters in CP1251 are not present in ISO8859-1. CP1251中的大多数非ASCII字符在ISO8859-1中不存在。 (CP1251 is Eastern European, and contains a lot of Cyrillic characters; ISO8859-1 is Western European, and contains a mix of accented Latin characters, punctuation, and symbols.) There are a few characters which are represented in both, but so few (and almost all of them are punctuation) that it probably won't do you any good. (CP1251是东欧语言,包含很多西里尔字符; ISO8859-1是西欧语言,并且包含重复的拉丁字符,标点符号和符号。)有两个字符代表两者,但很少(而且几乎所有这些都是标点符号)它可能对你没有任何好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM