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! (:
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
Re: Convert a String to an array of single characters?
Ha, that's easier than expected.
Thank you, kristof!