How to repeat a slice of bytes in Go

3 Answers

0 votes
package main
  
import (
    "fmt"
    "bytes"
)
  
func main() {
   slice := []byte{'G', 'O', 'L', 'A', 'N', 'G'}
          
   slicer := bytes.Repeat(slice, 2) 
  
   fmt.Printf("%s", slicer) 
}
  
  
  
/*
run:
  
GOLANGGOLANG
  
*/

 



answered May 24, 2020 by avibootz
0 votes
package main
  
import (
    "fmt"
    "bytes"
)
  
func main() {
   slice := []byte{'G', 'O', 'L', 'A', 'N', 'G'}
          
   slicer := bytes.Repeat(slice, 3) 
  
   fmt.Printf("%s", slicer) 
}
  
  
  
/*
run:
  
GOLANGGOLANGGOLANG
  
*/

 



answered May 24, 2020 by avibootz
0 votes
package main
  
import (
    "fmt"
    "bytes"
)
  
func main() {
   slicer := bytes.Repeat([]byte("GoLang"), 4)
  
   fmt.Printf("%s", slicer) 
}
  
  
  
/*
run:
  
GoLangGoLangGoLangGoLang
  
*/

 



answered May 24, 2020 by avibootz

Related questions

1 answer 264 views
2 answers 292 views
2 answers 228 views
2 answers 220 views
2 answers 267 views
2 answers 211 views
...