GopherSnippetsStar

Code snippets with tests and testable examples for the Go programming language

How to concatenate strings

Snippets Index - Run code on Go playground - Edit

package main

import (
	"fmt"
	"strings"
)

func Example() {
	// Create a slice of the strings that you want to join together
	strs := []string{"aa", "bb", "cc"}
	//Use the strings.Join function to join them, by passing the desired separator
	fmt.Println(strings.Join(strs, "-"))
	fmt.Println(strings.Join(strs, ", "))
	fmt.Println(strings.Join(strs, ""))
	// Output:
	// aa-bb-cc
	// aa, bb, cc
	// aabbcc
}

by psampaz - source code - comment below or here