我正在使用C#,Visual Studio 2010和Zoom.net创建一个客户端,以便从Z39.50服务器获取数据,但是我得到了一个难以理解的响应。
我注意到响应中包含的数字如response,但每行的内容在某些地方都不可读。我想这个问题只适用于用英语以外的语言编写的单词,这些特定单词的结果是数字或奇怪的符号。这是一个带有字节数组响应的file。
此屏幕截图是对我的客户的回复。
这是我的代码:
class Program
{
static void Main(string[] args)
{
try
{
using (var con = new Connection("url", port))
{
con.DatabaseName = "<name here>";
con.Syntax = Zoom.Net.RecordSyntax.GRS1;
var query = "@attr 1=21 @attr 2=3 @attr 3=3 @attr 4=2 " +
"@attr 5=100 @attr 6=1 \"John\"";
var results = con.Search(q);
for (uint i = 0; i < results.Size; i++)
{
string temp = Encoding.UTF8.GetString(results[i].Content);
}
}
}
catch(Exception exc)
{
Console.WriteLine(exc.Message);
Console.Read();
}
}
}
答案 0 :(得分:2)
问题解决了,我使用下面的自定义类进行希腊字符utf8编码。
namespace MARC
{
public class advancedGreekClass
{
protected byte[] inp;
protected int pos;
public advancedGreekClass(byte[] data)
{
inp = data;
pos = 0;
}
public string GetString()
{
var sb = new StringBuilder(1000000);
ulong ch;
for (; ; ) {
ch = read_advancegreek();
if (ch == 0) break;
sb.Append((char)ch);
}
return sb.ToString();
}
private ulong read_advancegreek()
{
int byteArraySize = inp.Length - pos;
ulong x = 0;
bool shift = false;
bool tonos = false;
bool dialitika = false;
while (byteArraySize > 0)
{
if (inp[pos] == 0x9d) //inp[i]
{
tonos = true;
}
else if (inp[pos] == 0x9e)
{
dialitika = true;
}
else if (inp[pos] == 0x9f)
{
shift = true;
}
else
break;
--byteArraySize;
pos++;
}
if (byteArraySize == 0)
{
return 0;
}
switch (inp[pos])
{
case 0x81:
if (shift)
if (tonos)
x = 0x0386;
else
x = 0x0391;
else
if (tonos)
x = 0x03ac;
else
x = 0x03b1;
break;
case 0x82:
if (shift)
x = 0x0392;
else
x = 0x03b2;
break;
case 0x83:
if (shift)
x = 0x0393;
else
x = 0x03b3;
break;
case 0x84:
if (shift)
x = 0x0394;
else
x = 0x03b4;
break;
case 0x85:
if (shift)
if (tonos)
x = 0x0388;
else
x = 0x0395;
else
if (tonos)
x = 0x03ad;
else
x = 0x03b5;
break;
case 0x86:
if (shift)
x = 0x0396;
else
x = 0x03b6;
break;
case 0x87:
if (shift)
if (tonos)
x = 0x0389;
else
x = 0x0397;
else
if (tonos)
x = 0x03ae;
else
x = 0x03b7;
break;
case 0x88:
if (shift)
x = 0x0398;
else
x = 0x03b8;
break;
case 0x89:
if (shift)
if (tonos)
x = 0x038a;
else
if (dialitika)
x = 0x03aa;
else
x = 0x0399;
else
if (tonos)
if (dialitika)
x = 0x0390;
else
x = 0x03af;
else
if (dialitika)
x = 0x03ca;
else
x = 0x03b9;
break;
case 0x8a:
if (shift)
x = 0x039a;
else
x = 0x03ba;
break;
case 0x8b:
if (shift)
x = 0x039b;
else
x = 0x03bb;
break;
case 0x8c:
if (shift)
x = 0x039c;
else
x = 0x03bc;
break;
case 0x8d:
if (shift)
x = 0x039d;
else
x = 0x03bd;
break;
case 0x8e:
if (shift)
x = 0x039e;
else
x = 0x03be;
break;
case 0x8f:
if (shift)
if (tonos)
x = 0x038c;
else
x = 0x039f;
else
if (tonos)
x = 0x03cc;
else
x = 0x03bf;
break;
case 0x90:
if (shift)
x = 0x03a0;
else
x = 0x03c0;
break;
case 0x91:
if (shift)
x = 0x03a1;
else
x = 0x03c1;
break;
case 0x92:
x = 0x03c2;
break;
case 0x93:
if (shift)
x = 0x03a3;
else
x = 0x03c3;
break;
case 0x94:
if (shift)
x = 0x03a4;
else
x = 0x03c4;
break;
case 0x95:
if (shift)
if (tonos)
x = 0x038e;
else
if (dialitika)
x = 0x03ab;
else
x = 0x03a5;
else
if (tonos)
if (dialitika)
x = 0x03b0;
else
x = 0x03cd;
else
if (dialitika)
x = 0x03cb;
else
x = 0x03c5;
break;
case 0x96:
if (shift)
x = 0x03a6;
else
x = 0x03c6;
break;
case 0x97:
if (shift)
x = 0x03a7;
else
x = 0x03c7;
break;
case 0x98:
if (shift)
x = 0x03a8;
else
x = 0x03c8;
break;
case 0x99:
if (shift)
if (tonos)
x = 0x038f;
else
x = 0x03a9;
else
if (tonos)
x = 0x03ce;
else
x = 0x03c9;
break;
default:
x = inp[pos];
break;
}
pos++;
return x;
}
//return new ulong();
}
}