473,781 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

I store the MSSqlServer is Nvarchar(unicod e),
the store data as "我就是我文本",
How can i decode in C#?
Nov 15 '05 #1
3 8130
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.Enc oding.Unicode.G etString(theByt es);

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_che n" <qu*********@as us.com.cn> wrote in message
news:OF******** ******@TK2MSFTN GP09.phx.gbl...
I store the MSSqlServer is Nvarchar(unicod e),
the store data as "我就是我文本",
How can i decode in C#?


Nov 15 '05 #2
Dmitriy Lapshin [C# / .NET MVP] <x-****@no-spam-please.hotpop.c om>
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.Enc oding.Unicode.G etString(theByt es);


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.co m>
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.Http Utility.HtmlDec ode( "我就是我文本" );


--
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
9386
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", line 60, in Run PS.Automation.Utility.System.AppendSystemPath(args, context) File "D:\ScriptRuntime\PS\Automation\Utility\System.py", line 55, in AppendSys temPath AppendPathVariable("PATH", appendtext, context) File...
0
1345
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 attribute error like this: AttributeError: 'unicode' object has no attribute 'decode' The code and data I am preparing is to work on postgres as well a sqlite so there are a couple of things I could do. I could always store any data as unicode...
2
10318
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
2
3425
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 script is described at http://www.paul.sladen.org/toys/samsung-yh-925/ I'm getting errors and hoping someone could give me some hints, for I have no python background.
4
5379
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: 'ascii' codec can't decode byte 0xXX in position 0: ordinal not in range(128) I spent two hours fixing it, and I hope it's done. The solution is one
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
3575
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 = meta.encode('unicode-escape') when given an 8-bit string, (in meta), the code fragment above yields the error below. 'ascii' codec can't decode byte 0xe1 in position 13: ordinal not in range(128)
2
4849
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: ======== sql = "INSERT INTO mytable (col1,col2) VALUES (?,?)" cursor.executemany(sql, records("test.tsv")) """
1
5778
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 Üü
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10308
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
10143
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...
1
10076
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9939
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6729
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
5375
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...
3
2870
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.