c# - Are null terminators part of text encoding? -
i'm trying read null terminated string byte array; parameter function encoding.
string readstring(encoding encoding) for example, "foo" in following encodings are:
utf-32: 66 00 00 00 6f 00 00 00 6f 00 00 00 utf-8: 66 6f 6f utf-7: 66 6f 6f 2b 41 41 41 2d if copied bytes array (reading null terminator) , passed array encoding.getstring(), wouldn't work because if string utf-32 encoded algorithm reach "null terminator" after second byte.
so sort of have double question: null terminators part of encoding? if not, how decode string character character , check following byte null terminator?
thanks in advance
(suggestions appreciated)
edit:
if "foo" null terminated , utf-32 encoded, be?:
1. 66 00 00 00 6f 00 00 00 6f 00 00 00 00 2. 66 00 00 00 6f 00 00 00 6f 00 00 00 00 00 00 00
the null terminator not "logically" part of string; it's not considered payload. it's used in c/c++ indicate string ends.
having said can have strings embedded \0's have careful ensure string doesn't appear truncated. example std::string doesn't have problem embedded \0's. if c_str() , and not account reported length() string appear cut off.
Comments
Post a Comment