// Go program to illustrate the concept // of splitting a slice of bytes package main import ( "bytes" "fmt" ) func main() { // Creating and initializing // the slice of bytes // Using shorthand declaration slice_1 := []byte{'!', '!', 'G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's', 'G', 'e', 'e', 'k', 's', '#', '#'} slice_2 := []byte{'A', 'p', 'p', 'p', 'p', 'l', 'e'} slice_3 := []byte{'%', 'g', '%', 'e', '%', 'e', '%', 'k', '%', 's', '%'} // Displaying slices fmt.Println("Original Slice:") fmt.Printf("Slice 1: %s", slice_1) fmt.Printf("\nSlice 2: %s", slice_2) fmt.Printf("\nSlice 3: %s", slice_3) // Splitting the slice of bytes // Using SplitN function res1 := bytes.SplitN(slice_1, []byte("eek"), 2) res2 := bytes.SplitN(slice_2, []byte(""), 3) res3 := bytes.SplitN(slice_3, []byte("%"), 0) // Display the results fmt.Printf("\n\nAfter splitting:\n") fmt.Printf("\nSlice 1: %s", res1) fmt.Printf("\nSlice 2: %s", res2) fmt.Printf("\nSlice 3: %s", res3) }