469,642 Members | 1,217 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,642 developers. It's quick & easy.

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 6266
[Yosi] <Yo**@discussions.microsoft.com> 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.WriteLine ((int)c);
}

--
Jon Skeet - <sk***@pobox.com>
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.Length;j++)
{
buffer[j]=Convert.ToByte(stR[j]);
}
string clientcommand = System.Text.Encoding.Unicode.GetString(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**@discussions.microsoft.com> 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.WriteLine ((int)c);
}

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

Nov 16 '05 #3
[Yosi] <Yo**@discussions.microsoft.com> wrote:
I want to see "4.1", I successfuly do that:
Byte[] buffer = new Byte[stR.Length];
for(int j=0;j<stR.Length;j++)
{
buffer[j]=Convert.ToByte(stR[j]);
}
string clientcommand = System.Text.Encoding.Unicode.GetString(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.com>
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\0t\0i\0o\0n\0a\0l\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\0t\0i\0o\0n\0a\0l\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**@discussions.microsoft.com> wrote:
I want to see "4.1", I successfuly do that:
Byte[] buffer = new Byte[stR.Length];
for(int j=0;j<stR.Length;j++)
{
buffer[j]=Convert.ToByte(stR[j]);
}
string clientcommand = System.Text.Encoding.Unicode.GetString(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.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5
[Yosi] <Yo**@discussions.microsoft.com> wrote:
I want to make an application includes one Text box, and 2 button , user can
write:
"\x2E\x03N\0a\0t\0i\0o\0n\0a\0l\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\0t\0i\0o\0n\0a\0l\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.Unicode.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.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Markus Hämmerli | last post: by
4 posts views Thread by fowlertrainer | last post: by
5 posts views Thread by Sonu | last post: by
10 posts views Thread by Nikolay Petrov | last post: by
24 posts views Thread by ChaosKCW | last post: by
4 posts views Thread by Rehceb Rotkiv | last post: by
7 posts views Thread by 7stud | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.