473,695 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unicode convert

Hi,
I have a string array includes unicode data, how can I print the char (real
string),
for example:
"\x08\x03\x34\0 .\0\x39\0"
What should I do, I want to see the char of this array of unicode.
I want to make convert between Unicode to string and string to Unicode.

Nov 16 '05 #1
5 6572
[Yosi] <Yo**@discussio ns.microsoft.co m> wrote:
I have a string array includes unicode data, how can I print the char (real
string),
for example:
"\x08\x03\x34\0 .\0\x39\0"
What should I do, I want to see the char of this array of unicode.
I want to make convert between Unicode to string and string to Unicode.


Strings are in Unicode already. If you mean you want to see:

8
3
52
0
etc

then just do:

foreach (char c in theString)
{
Console.WriteLi ne ((int)c);
}

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
I want to see "4.1", I successfuly do that:
Byte[] buffer = new Byte[stR.Length];
for(int j=0;j<stR.Lengt h;j++)
{
buffer[j]=Convert.ToByte (stR[j]);
}
string clientcommand = System.Text.Enc oding.Unicode.G etString(buffer );

****but I cant do the other way :
string str = "String to convert"
string unicodestring = str.Convert to Unicode ??????

"Jon Skeet [C# MVP]" wrote:
[Yosi] <Yo**@discussio ns.microsoft.co m> wrote:
I have a string array includes unicode data, how can I print the char (real
string),
for example:
"\x08\x03\x34\0 .\0\x39\0"
What should I do, I want to see the char of this array of unicode.
I want to make convert between Unicode to string and string to Unicode.


Strings are in Unicode already. If you mean you want to see:

8
3
52
0
etc

then just do:

foreach (char c in theString)
{
Console.WriteLi ne ((int)c);
}

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
[Yosi] <Yo**@discussio ns.microsoft.co m> wrote:
I want to see "4.1", I successfuly do that:
Byte[] buffer = new Byte[stR.Length];
for(int j=0;j<stR.Lengt h;j++)
{
buffer[j]=Convert.ToByte (stR[j]);
}
string clientcommand = System.Text.Enc oding.Unicode.G etString(buffer );

****but I cant do the other way :
string str = "String to convert"
string unicodestring = str.Convert to Unicode ??????


Why would you get 4.1 from "\x08\x03\x34\0 .\0\x39\0"?

The above is:

Backspace
ETX (not even sure what that is)
4
NUL
..
NUL
9
NUL

I think it would help if you started right from the beginning, and told
us what your original data is, where you get it from, and what you want
to do with it.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
I want to make an application includes one Text box, and 2 button , user can
write:
"\x2E\x03N\0a\0 t\0i\0o\0n\0a\0 l\0 \0S\0e\0m\0i\0" then click on convert to
ascii ->"National semi"

or write "National semi"
then click on convert to unicode ->
"\x2E\x03N\0a\0 t\0i\0o\0n\0a\0 l\0 \0S\0e\0m\0i\0"

I need this to use the result in the USB descriptor definistion

"Jon Skeet [C# MVP]" wrote:
[Yosi] <Yo**@discussio ns.microsoft.co m> wrote:
I want to see "4.1", I successfuly do that:
Byte[] buffer = new Byte[stR.Length];
for(int j=0;j<stR.Lengt h;j++)
{
buffer[j]=Convert.ToByte (stR[j]);
}
string clientcommand = System.Text.Enc oding.Unicode.G etString(buffer );

****but I cant do the other way :
string str = "String to convert"
string unicodestring = str.Convert to Unicode ??????


Why would you get 4.1 from "\x08\x03\x34\0 .\0\x39\0"?

The above is:

Backspace
ETX (not even sure what that is)
4
NUL
..
NUL
9
NUL

I think it would help if you started right from the beginning, and told
us what your original data is, where you get it from, and what you want
to do with it.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
[Yosi] <Yo**@discussio ns.microsoft.co m> wrote:
I want to make an application includes one Text box, and 2 button , user can
write:
"\x2E\x03N\0a\0 t\0i\0o\0n\0a\0 l\0 \0S\0e\0m\0i\0" then click on convert to
ascii ->"National semi"
Why would that convert to National semi though? What's the \x2E\x03
doing there to start with?
or write "National semi"
then click on convert to unicode ->
"\x2E\x03N\0a\0 t\0i\0o\0n\0a\0 l\0 \0S\0e\0m\0i\0" I need this to use the result in the USB descriptor definistion


I think the trouble is that you're sort of treating characters as if
they were bytes - you need to be very clear about the difference.
You're effectively using Encoding.Unicod e.GetBytes and then treating
each of those bytes as a character, which is likely to lead to problems
later on. Is there any reason for it not to end up as a binary block
which doesn't necessarily need to be cut/paste?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

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

Similar topics

6
24525
by: Markus Hämmerli | last post by:
I ' ll tra to convert a Cstring to char* without success. I working in a Unicode enabled environment this is working in Unicode CString source = _T("TestString"); TCHAR *szSource = source.GetBuffer(0 ); but i need a char* and so this is not working CString source = _T("TestString");
4
2029
by: fowlertrainer | last post by:
Hi ! I want to get the WMI infos from Windows machines. I use Py from HU (iso-8859-2) charset. Then I wrote some utility for it, because I want to write it to an XML file. def ToHU(s,NoneStr='-'): if s==None: s=NoneStr if not (type(s) in ):
3
7770
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a DB and display it onscreen. No matter which way I open the file, convert it to Unicode/leave it as is or what ever, I see all single bytes ok, but double bytes become 2 seperate single bytes. Surely there is an easy way to convert these mixed...
5
2547
by: Sonu | last post by:
Hello everyone and thanks in advance. I have a multilingual application which has been built in MFC VC++ 6.0 (non-Unicode). It support English German Hungarian so far, which has been fine. But now I need it to work on Russian computers and I realized that the application should be converted to Unicode to work in Russian. I am totally new to .NET so I'm not sure of this, but I read somewhere that if converted my apllication to .NET...
10
8060
by: Nikolay Petrov | last post by:
How can I convert DOS cyrillic text to Unicode
18
34132
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found Encoding.Convert, but that needs byte arrays. Thanks, /Ger
24
9056
by: ChaosKCW | last post by:
Hi I am reading from an oracle database using cx_Oracle. I am writing to a SQLite database using apsw. The oracle database is returning utf-8 characters for euopean item names, ie special charcaters from an ASCII perspective. I get the following error: > SQLiteCur.execute(sql, row)
4
2503
by: Rehceb Rotkiv | last post by:
Hello, I have this little grep-like program: ++++++++++snip++++++++++ #!/usr/bin/python import sys import re
7
4019
by: 7stud | last post by:
Based on this example and the error: ----- u_str = u"abc\u9999" print u_str UnicodeEncodeError: 'ascii' codec can't encode character u'\u9999' in position 3: ordinal not in range(128) ------
0
8647
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
8585
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
9004
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
8835
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...
0
7681
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
5842
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
4590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3023
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2285
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.