How can I get a character in a string by index?
Solution 1:
string s = "hello";
char c = s[1];
// now c == 'e'
See also Substring
, to return more than one character.
Solution 2:
Do you mean like this
int index = 2;
string s = "hello";
Console.WriteLine(s[index]);
string also implements IEnumberable<char>
so you can also enumerate it like this
foreach (char c in s)
Console.WriteLine(c);