|
-
December 13th, 2009, 01:13 AM
#1
Convert a String to an array of single characters?
Hi everyone!
(I am using MS' Visual C# 2008 Express, in case that makes any difference...)
What I want to do is this: Take the content of a string (e.g. "Hello") and 'convert' it to an array that stores each character seperately (e.g. { "H", "e", "l", "l", "o" }). Can somebody tell me how to do that?
Additionally, is there a function that returns the index of an entity within an array? That is, if I was searching for an "e" in { "H", "e", "l", "l", "o" }, it'd return 1.
Sorry if these questions are dumb but I find it hard to come up with good key words for a google search. :/
Thanks in advance! (:
Last edited by TryingToC#; December 13th, 2009 at 02:30 AM.
-
December 13th, 2009, 05:34 AM
#2
Re: Convert a String to an array of single characters?
Actually a string is an array of chars so you can just do this 
String s ="Hello";
then s[0] will be 'H' and s[1] will be 'e' and so on...
for the index you can use this:
String s="Hello";
textBox1.Text = "" + s.IndexOf('l');
wich will return 2 
greets kristof
-
December 13th, 2009, 05:44 AM
#3
Re: Convert a String to an array of single characters?
Ha, that's easier than expected.
Thank you, kristof!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|