How do I get the length of a string in bytes?
Thanks.
Perhaps if I explain what I want to do ...
I'm making a cgi that will create a JSONObject, I then want to return that object as a UTF8 encoded string complete with the Content-Length header
If you do yourString.len You get the length of the string content in byte. There is an extra byte for \0 at the end of the string but that's technically not part of the content.
I don't know if this is what Content-length expect but I would be surprise if Unicode length was used in headers.
is internally the same
almost - string adds a x00` character at the end of the bytes which is not counted - it's necessary to maintain compatibility with C - in particular, it means you can't safely cast a seq[char] to a string and a string will not quite look the same in memory as a corresponding seq[char]