473,379 Members | 1,201 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,379 software developers and data experts.

How can I decode the unicode?? that is very exigency

I store the MSSqlServer is Nvarchar(unicode),
the store data as "我就是我文本",
How can i decode in C#?
Nov 15 '05 #1
3 8109
Hi,

First parse the string to extract the numbers themselves and store them in
an array of ints. Then split each number to a couple of bytes (the high byte
is obtained as

(theNumber & 0xff00) >> 8

and the low one as

(theNumber & 0xff)

The resultant bytes should be stored in a byte array with capacity equal to
doubled number of character codes.

The low bytes should be stored first (i.e. in even indexes - 0, 2, 4) and
the high bytes second (in odd indexes - 1, 3, 5)

When the byte array is ready, use code like this:

string result = System.Text.Encoding.Unicode.GetString(theBytes);

P.S. If you store your data in a MS SQL database, why HTML encode them in
the database? Wouldn't it be more reasonable to store the data as unicode
text in the database and HTML-encode it only when the data are rendered to a
Web page?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Unit Testing and Integration Environment
http://x-unity.miik.com.ua
Deliver reliable .NET software

"qushui_chen" <qu*********@asus.com.cn> wrote in message
news:OF**************@TK2MSFTNGP09.phx.gbl...
I store the MSSqlServer is Nvarchar(unicode),
the store data as "我就是我文本",
How can i decode in C#?


Nov 15 '05 #2
Dmitriy Lapshin [C# / .NET MVP] <x-****@no-spam-please.hotpop.com>
wrote:
First parse the string to extract the numbers themselves and store them in
an array of ints. Then split each number to a couple of bytes (the high byte
is obtained as

(theNumber & 0xff00) >> 8

and the low one as

(theNumber & 0xff)

The resultant bytes should be stored in a byte array with capacity equal to
doubled number of character codes.

The low bytes should be stored first (i.e. in even indexes - 0, 2, 4) and
the high bytes second (in odd indexes - 1, 3, 5)

When the byte array is ready, use code like this:

string result = System.Text.Encoding.Unicode.GetString(theBytes);


That sounds like a lot of unnecessary work. Once you've parsed the
numbers as their 16 bit unicode values, just create a char array of the
right size, and set each char to be the appropriate value as parsed.
Then use the String(char[]) constructor. No need to split 16 bit
numbers into 2 bytes and then just recombine them :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #3
> the store data as "我就是我文本",
How can i decode in C#?


another solution:

string x = System.Web.HttpUtility.HtmlDecode( "我就是我文本" );


--
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_dotnet.html - http://dnetmaster.net/
Nov 15 '05 #4

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

Similar topics

4
by: Robin Siebler | last post by:
I have no idea what is causing this error, or how to fix it. The full error is: Traceback (most recent call last): File "D:\ScriptRuntime\PS\Automation\Handlers\SCMTestToolResourceToolsBAT.py",...
0
by: David Pratt | last post by:
Recently I have run into an issue with sqlite where I encode strings going into sqlite3 as utf-8. I guess by default sqlite3 is converting this to unicode since when I try to decode I get an...
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...
2
by: rsd | last post by:
Hi, I'm trying get Samsung YH-920 mp3 player to work with Debian GNU/Linux. To do that I need to run http://www.paul.sladen.org/toys/samsung-yh-925/yh-925-db-0.1.py script, the idea behind the...
4
by: Oleg Parashchenko | last post by:
Hello, I'm working on an unicode-aware application. I like to use "print" to debug programs, but in this case it was nightmare. The most popular result of "print" was: UnicodeDecodeError:...
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: Eric S. Johansson | last post by:
I'm having a problem (Python 2.4) converting strings with random 8-bit characters into an escape form which is 7-bit clean for storage in a database. Here's an example: body =...
2
by: Gilles Ganault | last post by:
Hello It seems like I have Unicode data in a CSV file but Python is using a different code page, so isn't happy when I'm trying to read and put this data into an SQLite database with APSW: ...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
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...

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.