Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert an int value to string in Go?

i := 123 s := string(i)  

s is 'E', but what I want is "123"

Please tell me how can I get "123".

And in Java, I can do in this way:

String s = "ab" + "c"  // s is "abc" 

how can I concat two strings in Go?

like image 621
hardPass Avatar asked Apr 11 '12 12:04

hardPass


1 Answers

Use the strconv package's Itoa function.

For example:

package main  import (     "strconv"     "fmt" )  func main() {     t := strconv.Itoa(123)     fmt.Println(t) } 

You can concat strings simply by +'ing them, or by using the Join function of the strings package.

like image 173
Klaus Byskov Pedersen Avatar answered Sep 30 '22 10:09

Klaus Byskov Pedersen