[英]How can I get a character in a string by index?
我知道我可以使用indexof()<\/code>函數返回字符串中特定字符的索引,但是如何返回特定索引處的字符呢?
"
string s = "hello";
char c = s[1];
// now c == 'e'
另請參閱Substring
,以返回多個字符。
你的意思是這樣嗎
int index = 2;
string s = "hello";
Console.WriteLine(s[index]);
string 也實現了IEnumberable<char>
所以你也可以像這樣枚舉它
foreach (char c in s)
Console.WriteLine(c);
function asdf (){ alert('asdf'); }<\/code><\/pre>
"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.