How to append string in golang?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today, we will learn to concatenate strings in golang, here we use the + operator to concate strings like javascript “LOVE ICON”…

In the following example, we are creating three variables and using the + operator to append one after one and after that storing in a new str variable.

Here, we are also using ” ” ( space ) as a separator.

package main
  
import "fmt"
  
func main() {
  
    // Creating and initializing strings
    str1 := "Welcome"
    str2 := "To"
    str3 := "aGuideHub"
  
    str := str1 + " " + str2 + " " + str3;
    fmt.Println("String: ", str)
  
}

In the above code, we have just created three variables, use the + operator concate, and output in front of you.

Output

Golang, append, string, example

Try it yourself

All the best 👍

Follow me on Twitter