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
+21.9k Golang : Repeat a character by multiple of x factor
+12.2k Golang : "https://" not allowed in import path
+5.3k PHP : Convert CSV to JSON with YQL example
+28.1k Golang : Read, Write(Create) and Delete Cookie example
+11.7k Golang : Convert a rune to unicode style string \u
+16.9k Golang : How to tell if a file is compressed either gzip or zip ?
+6.7k Golang : How to call function inside template with template.FuncMap
+6.3k Golang : How to determine if request or crawl is from Google robots
+6k Golang : Process non-XML/JSON formatted ASCII text file example
+13.9k Golang : Simple word wrap or line breaking example
+8.8k Golang : Intercept and compare HTTP response code example
+11.2k Golang : Find age or leap age from date of birth example