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
+7.5k Golang : Lock executable to a specific machine with unique hash of the machine
+8.9k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+8.3k Linux/Unix : fatal: the Postfix mail system is already running
+5.2k Gogland : Datasource explorer
+13.4k Golang : Image to ASCII art example
+31.2k Golang : Get local IP and MAC address
+14.3k Golang : Convert(cast) int to float example
+28.1k Golang : Change a file last modified date and time
+7.7k Golang : Gomobile init produce "iphoneos" cannot be located error
+23.4k Find and replace a character in a string in Go
+6.4k Golang : How to validate ISBN?
+8.2k Golang : Ackermann function example