473,786 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ConsoleApplicat ion1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{

string s = "??";

string encoded_s;
string restored_s;

Console.WriteLi ne("Source String : [{0}]" , s);

encoded_s=UTF7E ncoder(s);
Console.WriteLi ne("Encoded String : [{0}]" , encoded_s);

restored_s=UTF7 Decoder(encoded _s);
Console.WriteLi ne("Decoded String : [{0}]" , restored_s);

Console.ReadLin e();
}

public static string UTF7Encoder(str ing src)
{
return CodeConverter(s rc,Encoding.Def ault,Encoding.U TF7);
}

public static string UTF7Decoder(str ing src)
{
return CodeConverter(s rc,Encoding.UTF 7,Encoding.Defa ult);
}

private static string CodeConverter(s tring src, Encoding src_encoding,
Encoding dest_encoding)
{
byte[] array = new byte[src.Length];
array = src_encoding.Ge tBytes(src);
string s = dest_encoding.G etString(array) ;
return s;
}
}
}

Nov 16 '05 #1
1 5748
Hi Alex,

Your code is correct, however, it will not work for me as my Default encoding doesn't support chinese characters. Changing Encoding.Defaul t to Encoding.Unicod e 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
4768
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: <%@ page pageEncoding="UTF-8" %> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
1
2983
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 to complain when it hits the Chinese character, saying that it is an invalid token and thus it is not well-formed. This is the complaint of Python:
4
6522
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> <chinese>ÄÎ</chinese> </test>
8
3489
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 solve it ?? Private Sub Init() With AMSXML ..Formatting = Formatting.Indented ..Indentation = 4 ..IndentChar = " " ..WriteStartDocument()
2
10319
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 suit my purpose. >>> encoded = u'A\\nA' >>> decoded = encoded.decode('unicode_escape') >>> print len(decoded) 3 Note that both encoded and decoded are unicode string. I'm trying to use
19
32839
by: many_years_after | last post by:
Hi,everyone: Have you any ideas? Say whatever you know about this. thanks.
15
2310
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 an multi-bytes-char string, how did it determine to seperate the string every 2bytes or 1byte? My second question is: is there any one who has tested very long mbcs
1
5779
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 example: answer_str = raw_input(' Enter answer ') Herr Üü
2
6296
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 to be able to detect which characters are latin based and which are chinese ideographs. eg) a user may enter "hello ÐÂÎÅÍø world" this is because many Chinese search phrases (especially those involved with technology may include English words...
13
3930
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 Chinese characters, but neverthelss is unable to show them up on screen. The follow is some of the error message I received after I logged off the program: "Could not write output: <type "exceptions: UnicodeEncodeError'>, 'ascii' codec can't...
0
9496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8989
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.