Golang : How to join strings?
Apart from using fmt.Sprint()
function to combine strings together. There is another way to concatenate string from different strings. One of them is to use strings.Join()
function.
For example :
package main
import (
"fmt"
"strings"
)
func main() {
str := []string{"join", "this", "string", "with another", "string\n"}
fmt.Printf(strings.Join(str, " "))
strUTF := []string{"join", "is", "UTF8 safe", "我", "join", "你\n"}
fmt.Printf(strings.Join(strUTF, " "))
}
Output :
join this string with another string
join is UTF8 safe 我 join 你
See also : Golang : concatenate(combine) strings
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
+14.7k Golang : GUI with Qt and OpenCV to capture image from camera
+29.9k Golang : How to get HTTP request header information?
+11.7k Android Studio : Create custom icons for your application example
+7.2k Golang : Get environment variable
+6.6k Unix/Linux : How to get own IP address ?
+7k Golang : Fibonacci number generator examples
+52k Golang : How to get time in milliseconds?
+5k Golang : micron to centimeter example
+16.7k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+20k Golang : How to get time from unix nano example
+9.6k Golang : Validate IPv6 example
+14.8k Golang : Send email with attachment(RFC2822) using Gmail API example