ValidString in Go

Posted by GoDoc
Public (Editable by Users)

ValidString reports whether s consists entirely of valid UTF-8-encoded runes.

Go
Edit
package main

import (
	"fmt"
	"unicode/utf8"
)

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

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