Hello, I need to convert byte array to CP866 string on FEZ Domino. I use the following code, but it’s very slow…
Can anybody suggest any solution?
using System.Collections;
namespace Enc
{
class Encoding866
{
//symbols array
private static readonly ArrayList CharMap = new ArrayList(){
'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О',
'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э',
'Ю', 'Я', 'а', 'б', 'в', 'г', 'д', 'е', 'ж', 'з', 'и', 'й', 'к', 'л', 'м',
'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы',
'ь', 'э', 'ю', 'я', 'Ё', 'ё', 'Є', 'є', 'Ї', 'ї', 'Ў', 'ў','І','№','ÿ',
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157,
158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172,
173, 174, 175, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 73, 252, 255
};
//array length
private static readonly int ArrLength = CharMap.Count / 2;
//temp count var
private static int _iPos;
//get symbol code
private static int GetCharCode(char charIn)
{
_iPos = CharMap.IndexOf(charIn);
return _iPos > -1 ? (int)CharMap[ArrLength + _iPos] : (byte)charIn;
}
//get symbol
private static string GetChar(int codeIn)
{
_iPos = CharMap.IndexOf(codeIn);
return _iPos > -1 ? (CharMap[_iPos - ArrLength]).ToString() : ((char)codeIn).ToString();
}
//convert input string to bytes
public static byte[] GetBytes(string strInput)
{
var inCharData = strInput.ToCharArray();
var outBytes = new byte[inCharData.Length];
for (int i = 0; i < inCharData.Length; i++)
{
outBytes[i] = (byte)GetCharCode(inCharData[i]);
}
_iPos = 0;
return outBytes;
}
//convert input bytes to string
public static string GetString(byte[] byteInput)
{
var outString = string.Empty;
for (int i = 0; i < byteInput.Length; i++)
{
string strChar = GetChar(byteInput[i]);
if (strChar == "ÿ") strChar = string.Empty;
outString += strChar;
}
_iPos = 0;
return outString;
}
}
}