Valid in Go

Posted by GoDoc
Public (Editable by Users)

Valid reports whether p consists entirely of valid UTF-8-encoded runes.

Go
Edit
package main

import (
	"fmt"
	"unicode/utf8"
)

func main() {
	valid := []byte("Hello, 世界")
	invalid := []byte{0xff, 0xfe, 0xfd}

	fmt.Println(utf8.Valid(valid))
	fmt.Println(utf8.Valid(invalid))
}