Go lang's equivalent of charCode() method of JavaScript

前端 未结 2 578
故里飘歌
故里飘歌 2021-01-11 18:15

The charCodeAt() method in JavaScript returns the numeric Unicode value of the character at the given index, e.g.

\"s\".charCodeAt(0) // returns         


        
2条回答
  •  庸人自扰
    2021-01-11 18:54

    Internally string is a 8 bit byte array in golang. So every byte will represent the ascii value.

    str:="abc"
    byteValue := str[0]
    intValue := int(byteValue)
    fmt.Println(byteValue)//97
    fmt.Println(intValue)//97
    

提交回复
热议问题