Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1053

Does checking a prefix string by comparing to a byte slice fail?

$
0
0

I'm learning the book "Go Programing Language", when it introduce string, it says Go use utf-8 encoding system, so it's easy to check whether a string is a prefix/suffix of another base string. Use the functions below:

func HasPrefix(s, prefix string) bool {    return len(s) >= len(prefix) && s[:len(prefix)] == prefix}
func HasSuffix(s, suffix string) bool {    return len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix}

I wonder if there's any encoding system that would fail when using above functions to check prefix/suffix?


Viewing all articles
Browse latest Browse all 1053

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>