473,943 Members | 2,338 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 8421
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
8960
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
3651
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
9798
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
10316
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
29282
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
17622
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
10813
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
9970
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
11541
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...
1
11304
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
9866
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...
1
8232
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
7394
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
6090
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...
1
4914
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
4515
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.