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
+9.2k Golang : How to capture return values from goroutines?
+11.6k Golang : Handle API query by curl with Gorilla Queries example
+7.7k SSL : How to check if current certificate is sha1 or sha2 from command line
+12.9k Android Studio : Highlight ImageButton when pressed on example
+5.9k Golang : Markov chains to predict probability of next state example
+9.1k Golang : How to use Gorilla webtoolkit context package properly
+5k JQuery : Calling a function inside Jquery(document) block
+28.2k Golang : Move file to another directory
+13.7k Golang : reCAPTCHA example
+11.9k Golang : Verify Linux user password again before executing a program example
+10.3k Golang : Text file editor (accept input from screen and save to file)
+12.7k Golang : Get absolute path to binary for os.Exec function with exec.LookPath