如何按索引获取字符串中的字符? [英] How can I get a character in a string by index?
本文介绍了如何按索引获取字符串中的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以使用indexof()
函数返回字符串的特定字符的索引,但是如何在特定索引处返回字符?
I know that I can return the index of a particular character of a string with the indexof()
function, but how can I return the character at a particular index?
推荐答案
string s = "hello";
char c = s[1];
// now c == 'e'
另请参阅Substring
,以返回多个字符.
See also Substring
, to return more than one character.
这篇关于如何按索引获取字符串中的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文