Skip to content

Instantly share code, notes, and snippets.

@jbuchbinder
Created May 3, 2013 20:39
Show Gist options
  • Save jbuchbinder/5513891 to your computer and use it in GitHub Desktop.
Save jbuchbinder/5513891 to your computer and use it in GitHub Desktop.
Convert UTF-8 Go strings to ASCII bytes.
package main
import (
"unicode/utf8"
)
// Fake converting UTF-8 internal string representation to standard
// ASCII bytes for serial connections.
func StringToAsciiBytes(s string) []byte {
t := make([]byte, utf8.RuneCountInString(s))
i := 0
for _, r := range s {
t[i] = byte(r)
i++
}
return t
}
@inuoshios
Copy link

Thanks for the correction, @quite ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment