PC Review


Reply
Thread Tools Rate Thread

Conversin between chars and strings

 
 
Alfons
Guest
Posts: n/a
 
      7th Jan 2005
Hi,

How can I convert an array of chars into a string and vice
versa ?

char[] myChars = new char[10];

I want to convert these 10 chars into a single string, but
how ?

And if I have a single string, like

string ss = "abcdef";

How can I make an array of chars from this ?

Thx,
Alfons


 
Reply With Quote
 
 
 
 
Joakim Karlsson
Guest
Posts: n/a
 
      7th Jan 2005
Alfons wrote:
> Hi,
>
> How can I convert an array of chars into a string and vice
> versa ?
>
> char[] myChars = new char[10];
>
> I want to convert these 10 chars into a single string, but
> how ?


String str = new String(myChars);

> And if I have a single string, like
>
> string ss = "abcdef";
>
> How can I make an array of chars from this ?
>


char[] myChars = new char[ss.Length];
str.CopyTo((0, myChars , 0, str.Length);

/Joakim
 
Reply With Quote
 
Joerg Jooss
Guest
Posts: n/a
 
      7th Jan 2005
Alfons wrote:

> Hi,
>
> How can I convert an array of chars into a string and vice
> versa ?
>
> char[] myChars = new char[10];
>
> I want to convert these 10 chars into a single string, but
> how ?


string str = new string(mychars);


> And if I have a single string, like
>
> string ss = "abcdef";
>
> How can I make an array of chars from this ?


char[] chars = ss.ToCharArray();


It's all on MSDN...
--
http://www.joergjooss.de
mailto:news-(E-Mail Removed)
 
Reply With Quote
 
=?ISO-8859-1?Q?=22Anders_Nor=E5s_=5BMCAD=5D=22?=
Guest
Posts: n/a
 
      7th Jan 2005
Alfons wrote:
> char[] myChars = new char[10];
>
> I want to convert these 10 chars into a single string, but
> how ?

string myString=new string(myChars);

> And if I have a single string, like
>
> string ss = "abcdef";

char[] myChars=ss.ToCharArray();

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
Reply With Quote
 
Joakim Karlsson
Guest
Posts: n/a
 
      7th Jan 2005
Joakim Karlsson wrote:
>
> char[] myChars = new char[ss.Length];
> str.CopyTo((0, myChars , 0, str.Length);


Doh! Me stoopid!

Of course you should use:
char[] myChars = str.ToCharArray();

Bad Joakim! Bad!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with special chars in csharp strings? Alex Microsoft C# .NET 4 15th Feb 2007 03:14 PM
Word UNDO now does single chars not strings. Why? =?Utf-8?B?R2VvcmdlSG93YXJkQnJvd24=?= Microsoft Word Document Management 2 14th May 2006 04:55 PM
International strings/chars Dobieslaw Wroblewski Microsoft Dot NET Framework 5 2nd Jan 2005 07:49 AM
regex -- substitute chars outside quoted strings Gary McCullough Microsoft Dot NET 5 10th Nov 2004 05:54 PM
Q: about Strings and chars. Sky Microsoft C# .NET 4 4th Mar 2004 01:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:10 AM.