I'm running this code in Go Playground:
fmt.Println(strings.ContainsRune("\xa0", '\xa0'))
I'm wondering, why does it output false
? According to the docs, it says:
ContainsRune returns true if the Unicode code point r is within s.
It seems to me that the code point is there, it seems strange that it would give false
as a response.
"\x0a" is not a unicode code point.
fmt.Println(strings.ContainsRune("\u00a0", '\u00a0'))
Works, as expected.
Because it's not a valid unicode code point, looking at strings.IndexRune
func IndexRune(s string, r rune) int {
switch {
case r < 0x80:
.....
default:
.....
}
return -1
}
If you try utf8.ValidString("\xa0")
it will return false.