In Go language, strings are different from other languages like Java, C++, Python, etc. It is a sequence of variable-width characters where each and every character is represented by one or more bytes using UTF-8 Encoding.
In the Go strings, you are allowed to split the string after the specified separator using a SplitN() function. This function splits a slice into all substrings after each instance of the given separator and returns a slice of the substrings between those separators. The count indicates the number of subslices to return. It is defined under the string package so, you have to import string package in your program for accessing SplitN function.
func SplitN(str, sep string, m int) string
Here, str is the string and sep is the separator. If str does not contain the given sep and sep is non-empty, then it will return a slice of length 1 which contain only str. Or if the sep is empty, then it will split after each UTF-8 sequence. Or if both str and sep are empty, then it will return an empty slice.
Final Result after splitting: Slice 1: [****Welcome to GeeksforGeeks****] Slice 2: [Learning how to x trim x a x slice of bytes] Slice 3:  Slice 4: 
Original Strings: String 1: Welcome, to, Geeks, for, Geeks String 2: AppleAppleAppleAppleAppleApple String 3: %G%E%E%K%sS After splitting: String 1: [Welcome to, Geeks, for, Geeks] String 2: [A leA leAppleAppleAppleApple] String 3: 
- Golang | Splitting a slice of bytes after the specified separator
- Golang | Splitting the slice after the specified separator
- Golang | Splitting a Slice Separated by the Specified Expression
- How to split a slice of bytes after the given separator in Golang?
- How to find the index value of specified string in Golang?
- How to find the last index value of specified string in Golang?
- Check if the String starts with specified prefix in Golang
- Check if the String ends with specified suffix in Golang
- How to check the specified rune in Golang String?
- Golang | Checking the string for the specified regular expression
- How to Get the String in Specified Base in Golang?
- Check if the specified element is present in the slice of bytes in Golang
- Check if the Slice of bytes starts with specified prefix in Golang
- Check if the Slice of bytes ends with specified suffix in Golang
- How to replace a specified element in slice of bytes in Golang?
- Finding the index value of specified byte in slice of bytes in Golang
- How to find last index value of specified byte in slice of bytes in Golang?
- Golang | Checking the byte of slice for specified regular expression
- How to Map a Rune to the Specified Case in Golang?
- Finding Absolute Value For Specified Complex Number in Golang?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.