Hi group,
I am writing a RFC Server with SAP.NET Connector to connect to SAP. There
are chinese characters passing back and forth.
I found that all chinese characters sending from SAP are encoded with
UTF-7. In order to let SAP display chinese characters correctly, i also need
to encode my chinese data by UTF-7.
However, i need to convert the UTF-7 encoded SAP data back to chinese
character, but i tried in vain. I wrote a simple program to test it. but it
made me more confused. The following C# program try to encode the chinese
string "s" with UTF-7 and then decode it.
But i never get it back. What is wrong?
Regards,
Alex
============================================
using System;
using System.Text;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string s = "??";
string encoded_s;
string restored_s;
Console.WriteLine("Source String : [{0}]" , s);
encoded_s=UTF7Encoder(s);
Console.WriteLine("Encoded String : [{0}]" , encoded_s);
restored_s=UTF7Decoder(encoded_s);
Console.WriteLine("Decoded String : [{0}]" , restored_s);
Console.ReadLine();
}
public static string UTF7Encoder(string src)
{
return CodeConverter(src,Encoding.Default,Encoding.UTF7);
}
public static string UTF7Decoder(string src)
{
return CodeConverter(src,Encoding.UTF7,Encoding.Default);
}
private static string CodeConverter(string src, Encoding src_encoding,
Encoding dest_encoding)
{
byte[] array = new byte[src.Length];
array = src_encoding.GetBytes(src);
string s = dest_encoding.GetString(array);
return s;
}
}
}