【发布时间】:2016-10-29 02:05:29
【问题描述】:
我有以下问题:如果String 包含从ASCII 未知的char,它使用63。
因此我将编码更改为UTF8,但我知道char 可以有两个length 中的length,所以我得到一个超出范围的错误。
我该如何解决这个问题?
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
byte[] baInput = enc.GetBytes(strInput);
// Split byte array (6 Byte) in date (days) and time (ms) parts
byte[] baMsec = new byte[4];
byte[] baDays = new byte[2];
for (int i = 0; i < baInput.Length; i++)
{
if (4 > i)
{
baMsec[i] = baInput[i];
}
else
{
baDays[i - 4] = baInput[i];
}
}
【问题讨论】:
-
strInput的内容是什么? -
内容例如为:l¦h*
-
看起来您使用的是字节,而不是文本。首先不要使用字符串来存储它,而是使用字节数组。您首先如何获得
strInput? -
|是字符串的一部分吗? -
你问错问题了。您应该问的问题(最终导致您的解决方案)是:“我的源字符串有什么字符编码?”。其他一切都只是猜测,对任何人都没有用。
标签: c# encoding bytearray utf8-decode