Ejemplo n.º 1
0
        // aSourceField:	MARC字段数组。注意ArrayList每个元素要求为byte[]类型
        static int GetMarcRecordString(List <byte[]> aSourceField,
                                       Encoding encoding,
                                       out string[] saTarget)
        {
            string strField066Value = "";

            // 提前得到066字段
            for (int j = 1; j < aSourceField.Count; j++)
            {
                string strField     = Encoding.ASCII.GetString((byte[])aSourceField[j]);
                string strFieldName = "";
                if (strField.Length >= 5)
                {
                    strFieldName = strField.Substring(0, 3);
                }
                else
                {
                    continue;
                }

                if (strFieldName == "066")
                {
                    strField066Value = strField.Substring(5);
                    break;
                }
            }

            // 根据066字段内容提示Marc8Encoding切换状态
            saTarget = new string[aSourceField.Count];
            for (int j = 0; j < aSourceField.Count; j++)
            {
                if (encoding is Marc8Encoding)
                {
                    Marc8Encoding marc8 = (Marc8Encoding)encoding;
                    marc8.SetDefaultCodePage(strField066Value);
                    saTarget[j] = marc8.GetString((byte[])aSourceField[j]);
                }
                else
                {
                    // 一般编码方式
                    saTarget[j] = encoding.GetString((byte[])aSourceField[j]);
                }
            }

            return(0);
        }
Ejemplo n.º 2
0
        private void button_e2uStringConvert_Click(object sender, EventArgs e)
        {
            if (this.textBox_e2uFilename.Text == "")
            {
                MessageBox.Show(this, "尚未指定 e2u 码表文件");
                return;
            }

            this.textBox_unicodeCode.Text = "";

            CharsetTable charsettable_e2u = new CharsetTable();

            charsettable_e2u.Attach(this.textBox_e2uFilename.Text,
                                    this.textBox_e2uFilename.Text + ".index");

            Marc8Encoding encoding = new Marc8Encoding(charsettable_e2u,
                                                       this.MainForm.DataDir + "\\asciicodetables.xml");

            try
            {
                string strText = "";

                if (this.textBox_field066value.Text != "")
                {
                    encoding.SetDefaultCodePage(this.textBox_field066value.Text.Replace('|', (char)31));
                }

                encoding.Marc8_to_Unicode(
                    Encoding.ASCII.GetBytes(
                        this.textBox_eaccString.Text),
                    out strText);

                this.textBox_unicodeString.Text = strText;
            }
            finally
            {
                string strTemp1;
                string strTemp2;

                charsettable_e2u.Detach(out strTemp1,
                                        out strTemp2);
            }
        }