473,394 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Decode Chinese Character From UTF-7 Data

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;
}
}
}

Nov 16 '05 #1
1 5687
Hi Alex,

Your code is correct, however, it will not work for me as my Default encoding doesn't support chinese characters. Changing Encoding.Default to Encoding.Unicode fixed that, which may be your solution as well.

--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeff | last post by:
Having a problem displaying both german and chinese characters from a UTF-8 database on the same *.jsp page. Can make Chinese characters appear correctly by including the following lines: <%@...
1
by: Anthony Liu | last post by:
The following 4 lines of code parses an XML document very well if the XML document contains only English words. But when I insert one Chinese character into the XML document, then Python starts...
4
by: Knackeback | last post by:
Hi, I wrote a XML file with GNU emacs 21.2.2 and with chinese character content encoded in UTF-8. I wrote something like: <?xml version="1.0" encoding="UTF-8"?> <test> <chinese>¼»</chinese>...
8
by: Agnes | last post by:
In my .net ,i need to generate an xml file , however, user may input a chinese character, Then , the xml will got something unknow characters. the following is my code, Does anyone know how to...
2
by: aurora | last post by:
I have some unicode string with some characters encode using python notation like '\n' for LF. I need to convert that to the actual LF character. There is a 'unicode_escape' codec that seems to...
19
by: many_years_after | last post by:
Hi,everyone: Have you any ideas? Say whatever you know about this. thanks.
15
by: glacier | last post by:
I use chinese charactors as an example here. "'\\xc4\\xe3\\xba\\xc3\\xc2\\xf0'" My first question is : what strategy does 'decode' use to tell the way to seperate the words. I mean since s1 is...
1
by: anonymous | last post by:
1 Objective to write little programs to help me learn German. See code after numbered comments. //Thanks in advance for any direction or suggestions. tk 2 Want keyboard answer input, for...
2
by: Wassy | last post by:
Hi, i have a website which contains both chinese and english content which is stored in a database. Each record in the dB has an english and Chinese field. If a user enters a search string i have...
13
by: Liang Chen | last post by:
Hope you all had a nice weekend. I have a question that I hope someone can help me out. I want to run a Python program that uses Tkinter for the user interface (GUI). The program allows me to type...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.