Golang : concatenate(combine) strings
Once in a blue moon, a programmer will bound to process input strings and manipulate the strings into something meaningful ... just like combining DNA. In this tutorial, we will learn how to combine or concatenate(link) couple of strings together.
The code below used the fmt.Sprint() function to combine the three separated strings.
package main
import "fmt"
func main() {
chinese := "你好"
english := "Hello"
malay := "apa khabar"
concatenated := fmt.Sprint(chinese +" "+ english +" "+ malay)
fmt.Println(concatenated)
}
Output :
你好 Hello apa khabar
Is there any other ways to combine strings in Go ? I'm sure there is. Just that I've not figure it all out yet by the time of writing this tutorial. Share it in comment below if you have better ways to combine strings in Golang.
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+4.5k Javascript : How to loop over and parse JSON data?
+12.1k Golang : How to get a user home directory path?
+3.5k Javascript : How to show different content with noscript?
+29.4k Golang : How to convert(cast) string to IP address?
+10.6k Golang : flag provided but not defined error
+15.9k Golang : XML to JSON example
+9.5k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+15.8k Golang : Find file size(disk usage) with filepath.Walk
+13.5k Golang : Save(pipe) HTTP response into a file
+13k Golang : Convert IP version 6 address to integer or decimal number
+10.2k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+6k Golang : Levenshtein distance example