How can I get a character in a string by index?

前端 未结 2 1210
别那么骄傲
别那么骄傲 2020-11-27 23:08

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?<

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 23:57

    string s = "hello";
    char c = s[1];
    // now c == 'e'
    

    See also Substring, to return more than one character.

提交回复
热议问题