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
+7.4k Golang : Ackermann function example
+4.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+12.2k Golang : error parsing regexp: invalid or unsupported Perl syntax
+15.4k CodeIgniter/PHP : Create directory if does not exist example
+15.9k Golang : XML to JSON example
+8.7k Golang : Bcrypting password
+13.5k Golang : Submit web forms without browser by http.PostForm example
+11.8k Generate salted password with OpenSSL example
+5.9k Golang : Decode XML data from RSS feed
+7.4k Android Studio : Import third-party library or package into Gradle Scripts
+28.4k Golang : Get and Set User-Agent examples
+25.4k Golang : Force your program to run with root permissions