我想将字节向量转换为字符串。例如
\n[0x61, 0x62, 0x63, 0x64, 0x65]\n\n[0xe4, 0xbd, 0xa0, 0xe5, 0xa5, 0xbd] # or non-ASCII characters\nRun Code Online (Sandbox Code Playgroud)\n应转换为:
\n"abcde" # [0x61, 0x62, 0x63, 0x64, 0x65]\n"\xe4\xbd\xa0\xe5\xa5\xbd" # [0xe4, 0xbd, 0xa0, 0xe5, 0xa5, 0xbd]\nRun Code Online (Sandbox Code Playgroud)\n
您只需调用内置的String构造函数即可:
String(v::AbstractVector{UInt8})\n\n Create a new String object from a byte vector v containing UTF-8 encoded characters.\nRun Code Online (Sandbox Code Playgroud)\njulia> [0x61, 0x62, 0x63, 0x64, 0x65] |> String\n"abcde"\n\njulia> String([0xe4, 0xbd, 0xa0, 0xe5, 0xa5, 0xbd])\n"\xe4\xbd\xa0\xe5\xa5\xbd"\nRun Code Online (Sandbox Code Playgroud)\n