User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 397,625 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,454 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser:
Views: 11137 | Replies: 4
Reply
Join Date: Dec 2005
Posts: 1
Reputation: neelu421 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
neelu421 neelu421 is offline Offline
Newbie Poster

Copy string into an array

  #1  
Dec 28th, 2005
I have a string "Hello". How can I copy this string into an array in words e.g 'H', 'e', 'l', 'l', 'o'.

Thanks in advance
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: Ohio
Posts: 204
Reputation: plazmo is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: Copy string into an array

  #2  
Jan 1st, 2006
Originally Posted by neelu421
I have a string "Hello". How can I copy this string into an array in words e.g 'H', 'e', 'l', 'l', 'o'.

Thanks in advance

a string is nothing more then an array of chars, so if you want to split up the strings letters into a different string array seperatly you could do something like this:

			string myString = "blah";
			string[] myArray= new string[myString.Length];
			for(int i = 0; i<myString.Length; i++){

				myArray[i] = myString[i].ToString();
			}
Reply With Quote  
Join Date: Dec 2004
Posts: 1,590
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 34
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Copy string into an array

  #3  
Jan 3rd, 2006
As has been mentioned, a string IS an array, of characters. You can use it like an array already, so there isn't really a need to convert it explicity. Perhaps if we knew what you were trying to do, we could give better advice.
Reply With Quote  
Join Date: Jan 2006
Location: Its the internet... i am everywhere lol
Posts: 274
Reputation: f1 fan is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 10
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: Copy string into an array

  #4  
Jan 11th, 2006
string theString = "hello";
char[] theStringAsArray = s.ToCharArray();
Reply With Quote  
Join Date: Aug 2005
Location: Ohio
Posts: 204
Reputation: plazmo is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: Copy string into an array

  #5  
Jan 12th, 2006
Originally Posted by f1 fan
string theString = "hello";
char[] theStringAsArray = s.ToCharArray();


yes of course, some how i forgot about that
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C# Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C# Forum

All times are GMT -4. The time now is 9:01 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC