Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting int and long into string in Go

Tags:

go

I have concurrent routine like this,

Routine 1()
{
for 30 times
Send string
}

Routine 2 (out <-chan string)
{
for
case str := <- out:
        fmt.Println(str)
}

Now, I want to send from routine 1 string like, string + int + string + system time in nanosecond. Can anybody help me how can I achieve this.

like image 212
Arpssss Avatar asked Dec 03 '11 17:12

Arpssss


People also ask

How do I convert an int to a string in Golang?

In order to convert an integer value to string in Golang we can use the FormatInt function from the strconv package. FormatInt returns the string representation of i in the given base, for 2 <= base <= 36. The result uses the lower-case letters 'a' to 'z' for digit values >= 10.

Can you convert int to string?

We can convert int to String in java using String. valueOf() and Integer.

How do you change type in Go?

Go is a statically typed language, which means types of variables must be known at compile time, and you can't change their type at runtime.


1 Answers

Sorry, I asked it too early. It is possible like this:

out <- string + strconv.Itoa(int) + string + strconv.Itoa64(time.Nanoseconds())

Thanks.


Update (Go1): strconv.Itoa64 has been replaced by strconv.FormatInt.

like image 91
Arpssss Avatar answered Sep 20 '22 04:09

Arpssss