Standard library / unicode/utf8

utf8.Valid()

Reports whether all input bytes are valid UTF-8. Expected stdout: 'true false\n'.

Formal Syntax & Structure

go syntaxgo
func Valid(p []byte) bool

Parameters & Attributes

NameTypeDescription
p[]byteByte sequence or destination buffer, as specified.

Return Value

bool

Reports whether all input bytes are valid UTF-8.

Working Example

Example Snippetgo
package main
import (  "fmt"  "unicode/utf8")
func main() {  fmt.Println(utf8.Valid([]byte("é")), utf8.Valid([]byte{0xff}))}
Go Reference