How to split the string based on delimiter in Go Language?

Split function in Golang

The Split function is used to divide the input string into a slice of sub strings based on the separators. The split function is defined in the String package of Go language. We need to import the String package in our program for accessing the Split function.

Syntax for Split function

The first argument S is the Input string slices. The separator needs to specify in the second argument of Split function. The function split the string into a slice of sub string by the given separator and returns the values in an array.

Golang program to split the string based on delimiter

The input string contains the employee details such as Name,Designation,Location, Hire_Date and those values are separated by comma (,). Lets write the Golang program to split the values based on delimiter using Split function.

The slice of sub string are stored in the result variable. Since the returned values are array of strings, the for loop is used to print each values as below.

Output