How to index characters in a Golang string?

前端 未结 9 1858
小鲜肉
小鲜肉 2020-12-04 09:15

How to get an \"E\" output rather than 69?

package main

import \"fmt\"

func main() {
    fmt.Print(\"HELLO\"[1])
}

Does Golang have funct

9条回答
  •  隐瞒了意图╮
    2020-12-04 10:10

    The general solution to interpreting a char as a string is string("HELLO"[1]).

    Rich's solution also works, of course.

提交回复
热议问题