utf16(::Union{Ptr{UInt16},Ptr{Int16}}, length

utf16(::Union{Ptr{UInt16},Ptr{Int16}} [, length])

Create a string from the address of a NUL-terminated UTF-16 string. A copy is made; the pointer can be safely freed. If length is specified, the string does not have to be NUL-terminated.

Examples

In the Julia programming language, the function utf16(s)

Create a UTF-16 string from a byte array, an array of UInt16, or any other string type. The resulting UTF16String data is terminated by the NUL codepoint (16-bit zero), which is not treated as a character in the string.

julia> utf16("Hello")
"Hello\0"
julia> utf16([0x48, 0x65, 0x6C, 0x6C, 0x6F])
"Hello\0"

Note that the NUL character (\0) is automatically appended to the resulting UTF16String.

If you have a UInt16 array A that is already NUL-terminated valid UTF-16 data, then you can use UTF16String(A) to construct the string without making a copy of the data and treating the NUL as a terminator rather than as part of the string.

Common mistake example:

julia> utf16([0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x00])
"Hello\0\0"

In this example, an extra NUL character is added to the resulting UTF16String. It's important to ensure that the input data is valid UTF-16 and does not have any additional NUL characters.

See Also

ascii, base64decode, Base64DecodePipe, base64encode, Base64EncodePipe, bin, bits, bytestring, charwidth, chomp, chop, chr2ind, contains, endswith, escape_string, graphemes, ind2chr, iscntrl, istext, isupper, isvalid, join, lcfirst, lowercase, lpad, lstrip, normalize_string, num2hex, parseip, randstring, readuntil, replace, repr, rpad, rsplit, rstrip, search, searchindex, split, startswith, string, stringmime, strip, strwidth, summary, takebuf_string, ucfirst, unescape_string, uppercase, utf16, utf32, utf8, wstring,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: