tags:

views:

65

answers:

1

How can i encode my string as ascii byte array?

In go

+1  A: 

If you're looking for a conversion, just do byteArray := []byte(myString)

The language spec details conversions between strings and certain types of arrays (byte for bytes, int for Unicode points)

cthom06
Thanks, that was easy :)
tm1rbrt
I think cthom06 realizes this, but this isn't, strictly speaking, an "ASCII" byte array. It's more like a UTF-8 byte array. If the string contained non-ASCII characters, then the bytes for those characters will be here too. If you want your code to play well with different languages, that's something you should always keep in mind.
Evan Shaw
@Chickencha that's true. I kind of gave the quick and dirty answer. But i did mention the []int conversion for better unicode handling
cthom06