请参阅主题,请注意,此问题仅适用于.NET compact框架.这种情况发生在Windows Mobile 6 Professional SDK附带的模拟器以及我的英文HTC Touch Pro(所有.NET CF 3.5)上.iso-8859-1代表西欧(ISO),它可能是除了us-ascii之外最重要的编码(至少当一个用户网帖的数量).
我很难理解为什么不支持这种编码,而支持以下版本(同样在模拟器和我的HTC上):
那么,支持希腊语比支持德语,法语和西班牙语更重要吗?任何人都可以对此有所了解吗?
谢谢!
安德烈亚斯
spl*_*tne 15
我会尝试使用"windows-1252"作为编码字符串.根据维基百科,Windows-1252是ISO-8859-1的超集.
System.Text.Encoding.GetEncoding(1252)
Run Code Online (Sandbox Code Playgroud)
我稍后知道它,但我为编码 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;
}
}
}
Run Code Online (Sandbox Code Playgroud)