Reputation: 187
I am creating a client using C#, Visual Studio 2010 and Zoom.net to get data from a Z39.50 server but I am getting an unreadable response.
I noticed that the response contains numbers like this response but the content of every line is in some places unreadable. I guess the problem is only for words that are written in language other than English and the result for these specific words comes to numbers or strange symbols. Here is a file with the byte array response.
This screenshot is a response to my client.
Here is my code:
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();
}
}
}
Upvotes: 3
Views: 1069
Reputation: 187
The problem solved whed I used the custom class below for greek characters utf8 encoding.
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();
}
}
Upvotes: 2