For the first case, use the strconv
method. Itoa()
" to convert the numeric value to string and method len()
to check the file size. For the second situation, use rune(str)[position]
in which, position
represents the position of the string passed as parameter. Remember that you said 3
position, however since the vector starts with 0
, the return relative to the 3
position would be 9
. See:
package main
import ("fmt"
"strconv")
func main() {
str := strconv.Itoa(57890)
fmt.Println(len(str))
// index inicia com 0. então 2 representa a posição 3
fmt.Println(string([]rune(str)[0])) // saida 5
fmt.Println(string([]rune(str)[1])) // saida 7
fmt.Println(string([]rune(str)[2])) // saida 8
}
See funfando no play golang .