JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

string/bytes

core-api


    cfunction
    src/core/string.c on line 220, column 1

    (string/bytes str)

    Returns a tuple of integers that are the byte values of the string.


See also:chrstring/from-bytes2 examplesSign in to add an example
Loading...
# Some tips for working with bytes and unicode:
(string/bytes "что-нибудь")                         #> (209 135 209 130 208 190 45 208 189 208 184 ...
(print (string/from-bytes 208 176 208 177))         #> аб
(map string/from-bytes (string/bytes "что-нибудь")) #> @["\xD1" "\x87" "\xD1" "\x82" "\xD0" "\xBE" ...

# Print renders "\xD1" "\x87" as ч, as unicode characters may have multiple bytes
# So use apply:
(apply print (map string/from-bytes 
                  (string/bytes "что-нибудь")))     #> что-нибудь
veqqqPlayground
(string/bytes "hello") # => (104 101 108 108 111)
swlkrPlayground