473,489 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to convert unsignedshort[] to string ?

Hi Friends,

Using Remoting concept, i have send WCHAR[] values from VC++.net
applicaiton to C# applicaiton. In my C# application it is treated as
unsigned shot[]. I need to convert it back to string and display it.

I tried with TypeConverter.GetConverter().ConvertToString()
functionality. and String.Format() functionality. But i get the value
as "System.UInt16" as string.

Please help me to solve this issue.

Regards,
Prakash.

Dec 1 '05 #1
8 8322
I suggest you try as following:

ushort[] uShortArray = {65, 66, 32, 67};
char[] charArray = new char[uShortArray.Length];
Array.Copy(uShortArray, charArray, uShortArray.Length);
string s = new String(charArray);
Console.WriteLine(s);

Hope it helps,
Thi

Dec 1 '05 #2
C# is a bit different than C++ in handling the primative types...in fact,
quite a bit different. C# actually defines structures (UInt16, UInt32, etc)
and uses the familiar syntax from C++ (int, long, ushort) as aliases for the
new structures. The kewl thing is...in the UInt16 (or unsigned
short/ushort) structure there is a built in function to convert a ushort to
a string (as there is with all of the other primative types.) If you wanted
to write the value out to the console you might do this...

System.UInt16 newint = new System.UInt16();
newint = 16;
Console.WriteLine(newint.ToString());

This would then write out 16 to the screen.

Just remember that in C# all of the primative types have structures
associated with them, and in fact aren't primative types anymore. Your
familiar keywords in C++ have been turned into aliases that are COMPLETELY
interchangable with the newly defined structures in the System namespace.

Hope this helps,

Chris

--
Securing your systems is much like fighting off disease -- as long as you
maintain basic hygiene, you're likely to be okay, but you'll never be
invulnerable.

Steve Shah - Unix Systems Network Administrator
"Prakash" <p.************@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi Friends,

Using Remoting concept, i have send WCHAR[] values from VC++.net
applicaiton to C# applicaiton. In my C# application it is treated as
unsigned shot[]. I need to convert it back to string and display it.

I tried with TypeConverter.GetConverter().ConvertToString()
functionality. and String.Format() functionality. But i get the value
as "System.UInt16" as string.

Please help me to solve this issue.

Regards,
Prakash.

Dec 1 '05 #3
I wanted to correct a statement i made. I said they "aren't" primative
types anymore and that isn't true...they are still considered the primative
types but are encapsulated in structures now. Just wanted to cover my butt
from the flamers...

Chris

--
Securing your systems is much like fighting off disease -- as long as you
maintain basic hygiene, you're likely to be okay, but you'll never be
invulnerable.

Steve Shah - Unix Systems Network Administrator
"Chris Springer" <cs*****@adelphia.net> wrote in message
news:XM********************@adelphia.com...
C# is a bit different than C++ in handling the primative types...in fact,
quite a bit different. C# actually defines structures (UInt16, UInt32,
etc) and uses the familiar syntax from C++ (int, long, ushort) as aliases
for the new structures. The kewl thing is...in the UInt16 (or unsigned
short/ushort) structure there is a built in function to convert a ushort
to a string (as there is with all of the other primative types.) If you
wanted to write the value out to the console you might do this...

System.UInt16 newint = new System.UInt16();
newint = 16;
Console.WriteLine(newint.ToString());

This would then write out 16 to the screen.

Just remember that in C# all of the primative types have structures
associated with them, and in fact aren't primative types anymore. Your
familiar keywords in C++ have been turned into aliases that are COMPLETELY
interchangable with the newly defined structures in the System namespace.

Hope this helps,

Chris

--
Securing your systems is much like fighting off disease -- as long as you
maintain basic hygiene, you're likely to be okay, but you'll never be
invulnerable.

Steve Shah - Unix Systems Network Administrator
"Prakash" <p.************@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi Friends,

Using Remoting concept, i have send WCHAR[] values from VC++.net
applicaiton to C# applicaiton. In my C# application it is treated as
unsigned shot[]. I need to convert it back to string and display it.

I tried with TypeConverter.GetConverter().ConvertToString()
functionality. and String.Format() functionality. But i get the value
as "System.UInt16" as string.

Please help me to solve this issue.

Regards,
Prakash.


Dec 1 '05 #4
Hi Chris,

I already tried with ToString() method.. its not working.

Now i have achieved through Array.copy method.

Regards,
Prakash.

Dec 1 '05 #5
Well, I'm glad you solved your problem but that method seems like a very
round about way to do it. If you post your full snippet of code we might be
able to optimize it for you. If you're content then that's ok too :P

Good Luck!

Chris

--
Securing your systems is much like fighting off disease -- as long as you
maintain basic hygiene, you're likely to be okay, but you'll never be
invulnerable.

Steve Shah - Unix Systems Network Administrator
"Prakash" <p.************@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi Chris,

I already tried with ToString() method.. its not working.

Now i have achieved through Array.copy method.

Regards,
Prakash.

Dec 1 '05 #6
>Well, I'm glad you solved your problem but that method seems like a very
round about way to do it I suggested Array.Copy basing on the fact that ushort and char are both
unsigned 2-byte integer. In other cases, a type-safe approach is
iterating through the source array, cast each element to target type,
and fill-in the destination array.If you post your full snippet of code we might be
able to optimize it for you.

If there is something to optimized, I don't think it is for converting
array of ushort to array of char. It is: is there a way to unmarshall
WCHAR[] to a string instead of an array of ushort? The original poster
did not supply enough info to say.

Thi

Dec 1 '05 #7
Chris Springer <cs*****@adelphia.net> wrote:
Well, I'm glad you solved your problem but that method seems like a very
round about way to do it. If you post your full snippet of code we might be
able to optimize it for you. If you're content then that's ok too :P


I think you've misunderstood the problem. The idea isn't to convert the
unsigned short 32 to "32" - it's to convert that to space, convert 65
to 'A' etc - at least, that's what it sounds like...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 1 '05 #8
Prakash <p.************@gmail.com> wrote:
Using Remoting concept, i have send WCHAR[] values from VC++.net
applicaiton to C# applicaiton. In my C# application it is treated as
unsigned shot[]. I need to convert it back to string and display it.


Can you get it to treat it as a char[] instead (on the C# side)? That
*should* work, and would make things a lot simpler - you could then
just call the String constructor which takes a char array.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 1 '05 #9

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

Similar topics

2
8891
by: Joel Moore | last post by:
Maybe I'm just easily baffled after an all-nighter but I can't seem to figure out how to represent a BitArray as a hexadecimal string. For example: Dim outputBank As New BitArray(8) ...
4
3597
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
4
9700
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
3
10237
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
7
29149
by: patang | last post by:
I want to convert amount to words. Is there any funciton available? Example: $230.30 Two Hundred Thirty Dollars and 30/100
6
1407
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function...
4
5078
by: tshad | last post by:
I am trying to convert a string character to an int where the string is all numbers. I tried: int test; string stemp = "5"; test = Convert.ToInt32(stemp); But test is equal to 53.
9
17489
by: Marco Nef | last post by:
Hi there I'm looking for a template class that converts the template argument to a string, so something like the following should work: Convert<float>::Get() == "float"; Convert<3>::Get() ==...
0
10704
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
7108
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,...
0
7142
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,...
0
7181
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...
0
7352
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...
0
5445
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,...
0
4565
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...
0
3078
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...
0
1383
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 ...
1
618
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.