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
+6.3k Golang : Calculate US Dollar Index (DXY)
+10.4k Golang : Detect number of faces or vehicles in a photo
+36.5k Golang : Convert date or time stamp from string to time.Time type
+13.6k Golang : Strings comparison
+9.7k Golang : Copy map(hash table) example
+15.3k JavaScript/JQuery : Detect or intercept enter key pressed example
+8.3k Golang : HttpRouter multiplexer routing example
+12.4k Golang : Flush and close file created by os.Create and bufio.NewWriter example
+24.8k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+12.7k Golang : Exit, terminating or aborting a program
+5.5k Unix/Linux : How to archive and compress entire directory ?
+5.9k Golang : List all packages and search for certain package