473,714 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
+ 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.G etConverter().C onvertToString( )
functionality. and String.Format() functionality. But i get the value
as "System.UIn t16" as string.

Please help me to solve this issue.

Regards,
Prakash.

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

ushort[] uShortArray = {65, 66, 32, 67};
char[] charArray = new char[uShortArray.Len gth];
Array.Copy(uSho rtArray, charArray, uShortArray.Len gth);
string s = new String(charArra y);
Console.WriteLi ne(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.WriteLi ne(newint.ToStr ing());

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******** *************@g 14g2000cwa.goog legroups.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.G etConverter().C onvertToString( )
functionality. and String.Format() functionality. But i get the value
as "System.UIn t16" 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*****@adelph ia.net> wrote in message
news:XM******** ************@ad elphia.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.WriteLi ne(newint.ToStr ing());

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******** *************@g 14g2000cwa.goog legroups.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.G etConverter().C onvertToString( )
functionality. and String.Format() functionality. But i get the value
as "System.UIn t16" 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.goo glegroups.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*****@adelph ia.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.co m>
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.co m>
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
8939
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) outputBank(0) = True outputBank(1) = False outputBank(2) = False
4
3630
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 of the type the object is instantiated with. In my test program I have Option<std::string> and Option<long>. Here's the code for OptionBase and Option along with a small helper function. In the code are comments describing my problem, look closely...
4
9761
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 numeric value according to an arbitrary regular expression.
3
10286
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 and there you have it. So I enquired and found the Convert class with it's promising ToInt32 method, great... but it doesn't work. The thing keeps throwing Format Exceptions all over the place. What is the "C#" way to do this??? code int wmin,...
7
29239
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 declaration statments (first lines) e.g. Public Function ConvertCurrencyToEnglish(ByVal MyNumber As Double) As String Private Function ConvertHundreds(ByVal MyNumber As String) As String etc.
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
17551
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() == "3"; Convert<HelloWorld>::Get() == "HelloWorld"; The reason I need this is that in our design every class of a certain
0
10771
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 inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
8815
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
8713
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
9187
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
9080
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
4467
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...
0
4730
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3164
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
2529
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2113
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.