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
+13.8k Javascript : Prompt confirmation before exit
+5.8k Golang : Missing Subversion command
+17.8k Golang : Check if a directory exist or not
+16.5k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+13.9k Golang : How to convert a number to words
+9.9k Golang : How to profile or log time spend on execution?
+34.7k Golang : Upload and download file to/from AWS S3
+16.6k Golang : Capture stdout of a child process and act according to the result
+22.4k Golang : Round float to precision example
+6.9k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+5.7k Fontello : How to load and use fonts?
+15.2k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content