Standard library / unicode/utf8

utf8.ValidString()

Reports whether all bytes of a string are valid UTF-8; Go strings can hold arbitrary bytes. Expected stdout: 'true false\n'.

Formal Syntax & Structure

go syntaxgo
func ValidString(s string) bool

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.

Return Value

bool

Reports whether all bytes of a string are valid UTF-8; Go strings can hold arbitrary bytes.

Working Example

Example Snippetgo
package main
import (  "fmt"  "unicode/utf8")
func main() {  fmt.Println(utf8.ValidString("سلام"), utf8.ValidString("\xff"))}
Go Reference