Sobes.tech
Junior — Middle

Milliseid operatsioone tehakse string-andmete ühendamisel?

sobes.tech AI

Vastus AI-lt

In Go, string data concatenation is usually performed using the + operator or the strings.Join function.

  • The + operator simply concatenates two or more strings:
s := "Hello, " + "world!"
fmt.Println(s) // Hello, world!
  • The strings.Join function is used to join a slice of strings with a specified separator:
import "strings"

words := []string{"Go", "is", "awesome"}
result := strings.Join(words, " ")
fmt.Println(result) // Go is awesome

When concatenating strings, a new string is created containing the sequence of characters from the original strings. It is important to remember that strings in Go are immutable, so each concatenation creates a new string in memory.