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
+10.9k PHP : Convert(cast) bigInt to string
+12.3k Golang : Get month name from date example
+10.1k Golang : Read file and convert content to string
+23k Golang : Test file read write permission example
+8.5k Golang : How to check variable or object type during runtime?
+15.4k Golang : Get all local users and print out their home directory, description and group id
+9.4k Golang : Create unique title slugs example
+15.9k Golang : Get current time from the Internet time server(ntp) example
+21.3k Golang : How to force compile or remove object files first before rebuild?
+5.8k Golang : Find change in a combination of coins example
+6.2k Golang : Build new URL for named or registered route with Gorilla webtoolkit example