append a string to the end of another string in go

In Go, you can concatenate two strings using the + operator or the fmt.Sprintf function. Here's an example:

main.go
package main

import "fmt"

func main() {
    str1 := "Hello"
    str2 := ", World!"
    str3 := str1 + str2
    fmt.Println(str3)

    str4 := fmt.Sprintf("%s%s", str1, str2)
    fmt.Println(str4)
}
200 chars
14 lines

In the above example, both str1 + str2 and fmt.Sprintf concatenate str1 and str2 into a new string, which is then assigned to str3 and str4, respectively. The %s verb in fmt.Sprintf is a format specifier that tells the function to substitute the value of str1 and str2 as strings.

The output of the above code will be:

main.go
Hello, World!
Hello, World!
28 chars
3 lines

gistlibby LogSnag