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
+5.3k Golang : Extract sub-strings
+4.4k Python : Delay with time.sleep() function example
+31.2k Golang : How to check if a date is within certain range?
+13.1k Golang : How to determine if user agent is a mobile device example
+27.8k Golang : Save map/struct to JSON or XML file
+24.8k Golang : Convert(cast) string to uint8 type and back to string
+12k Golang : Calculate elapsed years or months since a date
+18.9k Nginx + FastCGI + Go Setup.
+11k Golang : List running EC2 instances and descriptions
+15.5k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+10.7k Golang : Detect user location with HTML5 geo-location
+4.6k Unix/Linux/MacOSx : Get local IP address