Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How can i split a Word into its letters in C-Sharp?

Here an Example:
Hello ---> H E L L O

After the "Split" the letters should be in a arraylist!
Posted
Comments
AspDotNetDev 14-Sep-10 17:51pm    
Unless you have a good reason to use ArrayList, use List instead.

Use a for loop to iterate over each letter in the string (it will loop from 0 to the length of the string, minus 1). You can then use the substring function to access each character. Once you have access to a given character, you can add it to a List that holds strings. FYI, I wrote out the answer rather than writing code so that you have a better understanding of the terminology and to be sure you code the solution yourself.
 
Share this answer
 
Sounds suspiciously like a homework question to me!

However, benefit of the doubt, so try :
<br />
Foreach (char c in string)
 
Share this answer
 
v2
Comments
Sandeep Mewara 14-Sep-10 11:40am    
Comment from OP: No!

I have to create a Hangmangame and the words in this game must be splittted up to control the letters if they are true or false.

Sorry. I don't speak the best english
The letters are already in a collection (what do you think a string is?)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900