how to convert array of string to string in golang?
September 10, 2022Hi Friends 👋,
Welcome To aGuideHub! ❤️
To convert array of string to string in golang, just use strings.Join()
method it will convert array of string to string. Only you have to pass array of string and seprator.
Follow the below tutorial if you are struggling with installing GO in windows.
https://aguidehub.com/blog/how-to-install-golang-in-windows/
Today, I will show you how do I convert array of string to string in golang, as above mentioned I’m going to use strings.Join()
way.
To use Join()
method we have to import "strings"
package.
Let’s start our Golang convert array of string to string example
main.go
package main
import (
"fmt"
"strings"
)
func main() {
stringArray := []string {"infinitbility.com","aguidehub.com","sortoutcode.com"}
justString := strings.Join(stringArray,",")
fmt.Println(justString)
}
In the above example, we have converted type []string
to string and printed in golang console. let’s check the output.
Output
infinitbility.com,aguidehub.com,sortoutcode.com
I hope it helps you, All the best 👍.