Itoa Versus String Of Rune
strconv.Itoa renders decimal digits while string(n) treats the integer as a Unicode code point, so the two are rarely interchangeable.
Code
package main
import (
"fmt"
"strconv"
)
func main() {
// strconv.Itoa renders decimal digits versus string(n), which treats the integer as a rune code point
fmt.Println("digits:", strconv.Itoa(65), strconv.Itoa(300))
fmt.Println("code points:", string(65), string(300))
// code points are how unicode lands in strings
fmt.Println("emoji:", string(rune(0x1F600)))
// negative or out-of-range values collapse to the replacement rune
fmt.Println("negative rune:", string(rune(-1)))
// the vet warning exists because string(65) is almost never what you meant
fmt.Println("round trip:", strconv.Itoa('A'), string(rune('A')))
}What drives the file
Itoa Versus String Of Rune keeps everything in the function main.
Using it
The demo output is labeled (digits:, code points:, emoji:); each label names the call that printed it.
Key statements
package main
Interactive Tools for This Topic
cURL to Python & Go ConverterTranslate curl CLI commands with headers, auth, JSON bodies, and timeouts into ready-to-run Python requests and Go net/http client code snippets.SRI Hash GeneratorGenerate Subresource Integrity (SRI) hashes from resource content using SHA-256, SHA-384, or SHA-512, and copy a ready-to-use script tag.
FAQ
- What does Itoa Versus String Of Rune print when run?
- Invoke the file as-is — the `digits:`, `code points:`, `emoji:` prefixes identify which step printed each line.
Report a problem with this exampleOpens a pre-filled issue on GitHub.