问题
I know that i could return the index of a particular character of a string with indexof() function. But how i could return the character with the particular index?
回答1:
string s = "hello";
char c = s[1];
// now c == 'e'
See also Substring
, to return more than one character.
回答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);
来源:https://stackoverflow.com/questions/2416894/how-to-return-the-character-which-is-at-the-index