To append a character to the end of a string in Go, you can use string concatenation with the + operator or the += operator.
In this example,
str1
with a string value of "Hello World"
.+
operator to append the character '!'
to str1
.package main
import "fmt"
func main() {
str1 := "Hello World"
str1 += "!"
fmt.Println(str1)
}
Hello World!
In this example,
str2
with a string value of "How are you"
.+=
operator to append the character '?'
to str2
.package main
import "fmt"
func main() {
str2 := "How are you"
str2 += "?"
fmt.Println(str2)
}
How are you?
In this tutorial, we learned How to Append a Character to end of a String in Go language with well detailed examples.