Go String Concatenation

Go provides several ways to concatenate strings. Use the + operator for a small number of values, strings.Join() for a slice of strings, and strings.Builder when constructing a string through repeated writes.

Concatenate Go Strings with the + Operator

The + operator is the simplest way to combine two or a few strings. The operands must be strings.

</>
Copy
result := string1 + string2

The following example inserts a space while concatenating two strings.

</>
Copy
package main

import "fmt"

func main() {
	first := "Hello"
	second := "World"
	result := first + " " + second

	fmt.Println(result)
}

Output

Hello World

String literals can also be combined at compile time by writing them next to the + operator.

</>
Copy
message := "Go " + "string " + "concatenation"

Concatenate a Slice of Strings with strings.Join()

Use strings.Join() when the values are stored in a []string and must be combined with the same separator between adjacent elements.

The syntax of strings.Join() function is:

</>
Copy
strings.Join(a []string, sep string)

where a is a string array and sep string is used between the joins of adjacent strings.

The function returns one string. It does not modify the original slice. When sep is an empty string, the elements are joined without a separator.

Join Two Go Strings with a Space

In the following program, we will take two strings and concatenate them using Join() function, with single space as a separator.

example.go

</>
Copy
package main

import (
	"fmt"
	"strings"
)

func main() {
	var str1 = "Hello"
	var str2 = "World"
	var output = strings.Join([]string{str1, str2}, " ")
	fmt.Println(output)
}

Output

Hello World

Join Multiple Go Strings with a Comma

In the following program, we have taken four strings in an a string array and joined them with the separator: comma ,.

example.go

</>
Copy
package main

import (
	"fmt"
	"strings"
)

func main() {
	var a = []string{"US", "Canada", "Europe", "Australia"}
	var sep = ","
	var output = strings.Join(a, sep)
	fmt.Println(output)
}

Output

US,Canada,Europe,Australia

Build a Go String Efficiently with strings.Builder

Repeatedly using + inside a loop can create intermediate strings. For incremental construction, strings.Builder provides WriteString(), WriteByte(), and WriteRune() methods.

</>
Copy
package main

import (
	"fmt"
	"strings"
)

func main() {
	words := []string{"Go", "makes", "string", "building", "clear"}

	var builder strings.Builder
	for i, word := range words {
		if i > 0 {
			builder.WriteByte(' ')
		}
		builder.WriteString(word)
	}

	fmt.Println(builder.String())
}

Output

Go makes string building clear

A builder should generally be used through a pointer and should not be copied after the first write. Call String() when the completed value is needed.

Concatenate a Go String and an Integer

Go does not implicitly convert an integer to a string during concatenation. Convert the integer with strconv.Itoa() or format the complete value with fmt.Sprintf().

</>
Copy
package main

import (
	"fmt"
	"strconv"
)

func main() {
	count := 12

	usingItoa := "Count: " + strconv.Itoa(count)
	usingSprintf := fmt.Sprintf("Count: %d", count)

	fmt.Println(usingItoa)
	fmt.Println(usingSprintf)
}

Output

Count: 12
Count: 12

Use strconv.Itoa() when only an integer-to-decimal-string conversion is required. Use fmt.Sprintf() when the result contains several values or needs formatting directives.

Append Bytes and Runes to a Go String

A Go string is immutable, so appending creates a new value. When working with raw bytes, convert the string to []byte, use append(), and convert the result back to a string.

</>
Copy
package main

import "fmt"

func main() {
	text := "Go"
	data := append([]byte(text), '!')

	fmt.Println(string(data))
}

Output

Go!

For a Unicode character represented by a rune, use a rune-aware operation such as builder.WriteRune() or append it to a []rune. A rune can occupy more than one byte in UTF-8.

</>
Copy
package main

import (
	"fmt"
	"strings"
)

func main() {
	var builder strings.Builder
	builder.WriteString("Go")
	builder.WriteRune('✓')

	fmt.Println(builder.String())
}

Output

Go✓

Go String Concatenation Method Comparison

MethodSuitable useSeparator handling
+ operatorCombining a small, fixed number of stringsAdd separators explicitly
strings.Join()Combining elements from a []stringOne separator is inserted between elements
strings.BuilderBuilding a string through repeated writes or loopsWrite separators conditionally
fmt.Sprintf()Combining strings with formatted numbers or other valuesControlled by the format string
[]byte or []runeByte-level or Unicode character-level manipulationHandled through append operations

Common Go String Concatenation Mistakes

  • Concatenating an integer directly: "Count: " + count does not compile when count is an integer. Convert it first.
  • Expecting automatic separators: the + operator does not insert spaces, commas, or line breaks.
  • Using strings.Join() with non-string values: its first argument must be a []string.
  • Adding a separator after every loop iteration: this can leave an unwanted trailing separator. Add it only between values.
  • Treating bytes as Unicode characters: use runes when each logical character must be handled correctly.

Go String Concatenation FAQs

What is the simplest way to concatenate two strings in Go?

Use the + operator, such as result := first + second. Add a literal separator when required, for example first + " " + second.

When should strings.Join() be used in Go?

Use strings.Join() when the values are already stored in a []string and the same separator should appear between each pair of elements.

How do you concatenate a string and an int in Go?

Convert the integer with strconv.Itoa(), as in "Count: " + strconv.Itoa(count), or use fmt.Sprintf("Count: %d", count).

Does Go support string interpolation?

Go does not provide interpolation syntax inside ordinary string literals. Use concatenation or formatting functions such as fmt.Sprintf().

Why use strings.Builder instead of + in a loop?

A builder is intended for incremental string construction and can avoid creating a new intermediate string for each concatenation step. For a small fixed expression, the + operator remains clearer.

Go String Concatenation Editorial QA Checklist

  • Confirm that every strings.Join() example imports the strings package.
  • Check that separators in the explanation match the separators used in the code and output.
  • Verify that integer examples explicitly convert or format the integer before concatenation.
  • Ensure byte and rune examples explain the difference between UTF-8 bytes and Unicode code points.
  • Run each Go program and compare its output with the displayed output block.

Summary of String Concatenation in Go

Use + for straightforward concatenation, strings.Join() for string slices, and strings.Builder for repeated construction. Convert integers and other non-string values before using them in a concatenated result.

In this Go Tutorial, we learned how to concatenate strings using the + operator, strings.Join(), strings.Builder, formatting functions, bytes, and runes.