Golang String Concatenation - Tutorial Kart
Golang String Concatenation
String Concatenation in Golang
To concatenate strings in Golang, you can use strings.Join() function. The syntax of strings.Join()
function is:
strings.Join(a []string, sep string)
where a is a string array and sep string is used between the joins of adjacent strings.
Golang String Concatenation Examples
Example 1 ¨C String Concatenation
In this example, we will take two strings and concatenate them using Join() function.
example.go
package main
import "fmt"
import "strings"
func main() {
var str1 = "Golang"
var str2 = "Tutorial"
var output = strings.Join([]string{str1, str2}, " ")
fmt.Println(output)
}
Output
Example 2 ¨C Join Strings with a Separator
In this example, we will take four strings in an a string array and join them with separator comma , .
example.go
package main
import "fmt"
import "strings"
func main() {
var a = []string{"US", "Canada", "Europe", "Australia"}
var sep = ","
var output = strings.Join(a, sep)
fmt.Println(output)
}
Output
Conclusion
In this Golang Tutorial, we learned how to concatenate string using Join() method.
Golang
? Golang Tutorial
? Run Golang Program
? Golang If Else
? Golang Switch
? Golang For Loop
? Golang Comments
? Golang Functions
? Golang Array
? Golang Slice
? Golang Slice
? Golang Struct
? Golang Class
? Golang Range
? Golang Map
? Golang Goroutine
? Golang Channel
Golang String Operations
? Golang String Length
? Golang String Concatenation
? Golang Split String
? Golang String - Get Index of Substr
? Golang String to Uppercase
? Golang String to Lowercase
? Golang Convert String to Integer
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- golang template array join
- golang string concatenation tutorial kart
- modernizing desktop linux development
- strip in python example
- declare array of maps
- avro schema to golang struct
- add elements to array after declaring it
- golang declare variable in for loop
- notice array to string conversion in php
- go go gadget go lang