How to index characters in a Golang string?

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

    You can also try typecasting it with string.

    package main
    
    import "fmt"
    
    func main() {
        fmt.Println(string("Hello"[1]))
    }
    

提交回复
热议问题