How to convert a char[] of integers to a string.

S

Steve Kershaw

I can convert from a string to a char array (char[]) by using
string.ToCharArray() function. Now how do I convert it back?

The string looks like this: "000457". I've converted it to a char
array: char[] = {0, 0, 0, 4, 5, 7}. Now I need to convert it back to a
string.

Thanks in advance for your help.

Steve
 
M

Mark Fitzpatrick

It's so simply you're going to want to kick yourself, it's also so simple
that it's going to get overlooked.

string mystring = new string(charArray);

if you look at the overloaded constructor for the string class, you'll
notice that one of the parameters is a char array. This "should" work just
fine though I haven't toyed with it in a long time.
 
S

Steve Kershaw

It's so simply you're going to want to kick yourself, it's also so simple
that it's going to get overlooked.

string mystring = new string(charArray);

if you look at the overloaded constructor for the string class, you'll
notice that one of the parameters is a char array. This "should" work just
fine though I haven't toyed with it in a long time.

--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006




I can convert from a string to a char array (char[]) by using
string.ToCharArray() function. Now how do I convert it back?
The string looks like this: "000457". I've converted it to a char
array: char[] = {0, 0, 0, 4, 5, 7}. Now I need to convert it back to a
string.
Thanks in advance for your help.
Steve- Hide quoted text -

- Show quoted text -

You are right! I did kick myself for overlooking the simple solution.
Thanks for your help!!!!

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top