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 :
Advertisement
Something interesting
Tutorials
+14.3k Golang : Simple word wrap or line breaking example
+14.5k Golang : How to check if your program is running in a terminal
+6.7k Golang : Output or print out JSON stream/encoded data
+18.5k Golang : Aligning strings to right, left and center with fill example
+10.3k Golang : How to check if a website is served via HTTPS
+12.5k Golang : Arithmetic operation with numerical slices or arrays example
+6k Golang : Experimenting with the Rejang script
+18.5k Golang : Example for RSA package functions
+87.7k Golang : How to convert character to ASCII and back
+11.1k Golang : How to determine a prime number?
+13.7k Golang : Activate web camera and broadcast out base64 encoded images
+9.9k Golang : Translate language with language package example