Answer the question
In order to leave comments, you need to log in
How to convert string to string from ASC II codes?
In the following, I have a certain string, I want to take each character from this string, convert it to ASCII code
and write the code itself into a string, instead of a character. In Python, this was done simply, in go I can’t think of it.
What I did:
There is a string word := "something"
If you execute fmt.Println(word[0]), then the code for the letter s will be printed, namely 115.
I tried this code
package main
import "fmt"
func main() {
var new_word string = ""
word:= "something"
for _, val := range word {
new_word += string(val)
}
fmt.Println(new_word)
}
Answer the question
In order to leave comments, you need to log in
Towards the strconv module
package main
import (
"fmt"
"strconv"
)
func main() {
var new_word string = ""
word: = "something"
for _, val: = range word {
new_word += strconv.Itoa(int(val))
}
fmt.Println(new_word)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question