How can I get the bytes in a UTF-8 character like
'é' without allocating?
My use case is a
for loop on all characters in a string. The loop must sometimes access the bytes directly:
for c in str # Do some work if some_condition # process each byte in `c` end end
This seems surprisingly difficult… Here are the solutions I found but they both allocate:
c = 'é' # First method codeunits(string(c)) # Second method (allows to preallocate and reuse the buffer) buf = IOBuffer() write(buf, c) take!(buf)