utf32(::Union{Ptr{Char},Ptr{UInt32},Ptr{Int32

utf32(::Union{Ptr{Char},Ptr{UInt32},Ptr{Int32}} [, length])

Create a string from the address of a NUL-terminated UTF-32 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

The utf32(s) function in Julia is used to create a UTF-32 string from different input types, such as byte arrays, arrays of Char, UInt32, or any other string type. The resulting UTF32String data is terminated by the NUL codepoint (32-bit zero) for compatibility with external functions requiring NUL-terminated data.

Here are some examples of how the utf32(s) function can be used:

  1. Create a UTF-32 string from a byte array:

    julia> bytes = [0x00, 0x48, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00, 0x6f, 0x00];
    julia> str = utf32(bytes)
    "Hello"
  2. Convert an array of Char to UTF-32 string:

    julia> chars = ['J', 'u', 'l', 'i', 'a'];
    julia> str = utf32(chars)
    "Julia"
  3. Convert an array of UInt32 to UTF-32 string:

    julia> codepoints = UInt32[0x0048, 0x0065, 0x006c, 0x006c, 0x006f];
    julia> str = utf32(codepoints)
    "Hello"
  4. Create a UTF-32 string from different string types:
    julia> str = utf32("Hello")
    "Hello"

It's important to note that the resulting UTF32String is terminated by a NUL codepoint (32-bit zero), which is not treated as a character in the string. This allows the string to be directly passed to external functions requiring NUL-terminated data.

If you already have a Char or UInt32 array A that is already NUL-terminated UTF-32 data, you can use UTF32String(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.

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: