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
+4.3k Golang : Frobnicate or tweaking a string example
+5k AWS S3 : Prevent Hotlinking policy
+7.8k Golang : How to extract video or image files from html source code
+9.9k Golang : How to pipe input data to executing child process?
+13.8k Golang : How to get Unix file descriptor for console and file
+8.2k Golang : Qt Yes No and Quit message box example
+8.7k PHP : Get coordinates latitude/longitude from string
+13.9k Golang : Get digits from integer before and after given position example
+6.2k Golang : Word limiter example
+7k Golang : Find relative luminance or color brightness
+18.5k Golang : Set or Add HTTP Request Headers
+12.7k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example