请参见subject,请注意此问题仅适用于.NET 紧凑框架。这发生在WindowsMobile6Professional SDK附带的仿真器上,以及我的英语HTC (全是.NET CF3.5)上。iso-8859-1代表西欧(ISO),这可能是除了我们之外最重要的编码方式-ascii(至少当我们使用usenet的帖子数时)。
我很难理解为什么不支持这种编码,而支持以下编码(同样在两个模拟器& my上):
那么,支持希腊语比支持德语、法语和西班牙语更重要吗?有人能解释一下这件事吗?
谢谢!
安德烈亚斯
发布于 2008-12-29 21:15:23
我会尝试使用"windows-1252“作为编码字符串。根据维基百科,Windows1252是ISO-8859-1的超集.
System.Text.Encoding.GetEncoding(1252)发布于 2008-12-29 21:13:36
这篇MSDN文章说:
.NET支持所有设备上的字符编码: Unicode (BE和LE)、UTF8、UTF7和ASCII。 对代码页编码的支持有限,并且只有当该编码被设备的操作系统识别时。 如果设备上没有所需的编码,则.NET Compact将抛出一个PlatformNotSupportedException。
我相信ISO编码的所有(或至少很多)都是代码页编码,属于“有限支持”规则。UTF8可能是你最好的替代品。
发布于 2014-07-07 20:01:16
我知道这有点晚了,但是我实现了编码ISO-8859-1的.net cf,我希望这能有所帮助:
namespace System.Text
{
public class Latin1Encoding : Encoding
{
private readonly string m_specialCharset = (char) 0xA0 + @"¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
public override string WebName
{
get { return @"ISO-8859-1"; }
}
public override int CodePage
{
get { return 28591; }
}
public override int GetByteCount(char[] chars, int index, int count)
{
return count;
}
public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
{
if (chars == null)
throw new ArgumentNullException(@"chars", @"null array");
if (bytes == null)
throw new ArgumentNullException(@"bytes", @"null array");
if (charIndex < 0)
throw new ArgumentOutOfRangeException(@"charIndex");
if (charCount < 0)
throw new ArgumentOutOfRangeException(@"charCount");
if (chars.Length - charIndex < charCount)
throw new ArgumentOutOfRangeException(@"chars");
if (byteIndex < 0 || byteIndex > bytes.Length)
throw new ArgumentOutOfRangeException(@"byteIndex");
for (int i = 0; i < charCount; i++)
{
char ch = chars[charIndex + i];
int chVal = ch;
bytes[byteIndex + i] = chVal < 160 ? (byte)ch : (chVal <= byte.MaxValue ? (byte)m_specialCharset[chVal - 160] : (byte)63);
}
return charCount;
}
public override int GetCharCount(byte[] bytes, int index, int count)
{
return count;
}
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
{
if (chars == null)
throw new ArgumentNullException(@"chars", @"null array");
if (bytes == null)
throw new ArgumentNullException(@"bytes", @"null array");
if (byteIndex < 0)
throw new ArgumentOutOfRangeException(@"byteIndex");
if (byteCount < 0)
throw new ArgumentOutOfRangeException(@"byteCount");
if (bytes.Length - byteIndex < byteCount)
throw new ArgumentOutOfRangeException(@"bytes");
if (charIndex < 0 || charIndex > chars.Length)
throw new ArgumentOutOfRangeException(@"charIndex");
for (int i = 0; i < byteCount; ++i)
{
byte b = bytes[byteIndex + i];
chars[charIndex + i] = b < 160 ? (char)b : m_specialCharset[b - 160];
}
return byteCount;
}
public override int GetMaxByteCount(int charCount)
{
return charCount;
}
public override int GetMaxCharCount(int byteCount)
{
return byteCount;
}
}
}https://stackoverflow.com/questions/398621
复制相似问题