How to trim a slice of bytes in Go

2 Answers

0 votes
package main
  
import (
    "fmt"
    "bytes"
)
  
func main() {
   slice := []byte{'!', '*', 'g', 'o', 'l', 'a', 'n', 'g', '@', '@', '@'}

   slicet:= bytes.Trim(slice, "!*@") 
  
   fmt.Printf("%s", slicet) 
}
  
  
  
/*
run:
  
golang
  
*/

 



answered May 24, 2020 by avibootz
0 votes
package main
  
import (
    "fmt"
    "bytes"
)
  
func main() {
   slicet:= bytes.Trim([]byte("***Go Lang***!"), "*!") 
  
   fmt.Printf("%s", slicet) 
}
  
  
  
/*
run:
  
Go Lang
  
*/

 



answered May 24, 2020 by avibootz

Related questions

2 answers 213 views
4 answers 326 views
4 answers 330 views
1 answer 264 views
2 answers 289 views
2 answers 226 views
...