Пример #1
0
        private static string GetText(byte[] data, int ts, int length, bool not, bool more)
        {
            string rst = "";
            int    i   = ts;

            while (i < ts + length)
            {
                if (data[i] == 0 && !more)
                {
                    break;
                }

                int b1 = not ? 0xFF - data[i++] : data[i++];

                if (b1 == 0)
                {
                    rst += '龘';
                }
                else if (b1 < 0x80)
                {
                    if (b1 == 0x0A)
                    {
                        rst += "{换行}";
                    }
                    else if (b1 == 0x0D)
                    {
                        rst += "{回车}";
                    }
                    else
                    {
                        rst += (char)b1;
                    }
                }
                else if (b1 >= 0xA0 && b1 <= 0xDF)
                {
                    if (b1 == 0xA0)
                    {
                        rst += "{结束}";
                    }
                    else
                    {
                        rst += sp[b1 - 0xA0];
                    }
                }
                else
                {
                    int b2  = not ? 0xFF - data[i++] : data[i++];
                    int jis = (b1 << 8) | b2;


                    if (!ct.IsJIS(jis))
                    {
                        throw new Exception();
                    }

                    int ucs = ct.JIS2UCS(jis);

                    rst += (char)ucs;
                }
            }

            {
                while (rst[rst.Length - 1] == '龘')
                {
                    rst = rst.Substring(0, rst.Length - 1);
                }
                rst = rst.Replace("龘", "{00}");
            }


            if (rst.Length > 0 && rst[0] == '`')
            {
                rst = rst.Substring(1);
                int kkk = rst.IndexOf('「');
                if (kkk == -1)
                {
                    return(rst);
                }

                string numS = rst.Substring(0, kkk);

                int num;
                if (int.TryParse(numS, out num))
                {
                    rst = sp_names[num - 1] + rst.Substring(kkk);
                }
            }
            return(rst);
        }