Go bytes Package Split()

Description

Go bytes Package Split()

package main/*from   w  ww. j  a v  a 2  s  . c o  m*/

import (
  "bytes"
  "fmt"    
)

func main() {  
  bytesValue := []byte("this is a test from java2s.com")
  space := []byte{' '}
  splitExample := bytes.Split(bytesValue, space)
  fmt.Printf("\nSplit split %q on a single space:", bytesValue)
  
  for index,element := range splitExample{
        fmt.Printf("\n%d => %q", index, element)
    }
  
  joinChar := []byte{'-'}
  bytesJoin := bytes.Join(splitExample,joinChar)
  fmt.Printf("\n\nJoin joins slice with '-' : %q", bytesJoin)  
    
  fmt.Printf("\nEqual Checks Byte Slice:%v",bytes.Equal(bytesJoin,bytesValue)) 
  bytesJoin = bytes.Join(splitExample,space)
  fmt.Printf("\nEqual Checks Byte Slice:%v",bytes.Equal(bytesJoin,bytesValue)) 
}



PreviousNext

Related