Golang bytes.Runes() function example

bytes

Runes returns a slice of runes (Unicode code points) equivalent to given input

Golang bytes.Runes() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {
 str := []byte("abcdefgh  abc  abc xyz abc")

 replace := bytes.Replace(str, []byte("abc"), []byte("cba"), 2)

 fmt.Println(string(replace))


 replaceall := bytes.Replace(str, []byte("abc"), []byte("cba"), -1)

 fmt.Println(string(replaceall))
 }

Output :

abcd

abcd

你好!

你好!

Reference :

http://golang.org/pkg/bytes/#Runes

Advertisement