How to index characters in a Golang string?

前端 未结 9 1870
小鲜肉
小鲜肉 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:12

    String characters are runes, so to print them, you have to turn them back into String.

    fmt.Print(string("HELLO"[1]))

提交回复
热议问题