Main Content

native2unicode

Convert numeric bytes to Unicode characters

    Description

    unicodestr = native2unicode(bytes) converts a numeric vector of bytes to the corresponding Unicode® characters using the default encoding scheme. The output unicodestr is a character vector that has the same array shape as bytes.

    If you specify bytes as a character vector or a string scalar, the function returns the same text value.

    example

    unicodestr = native2unicode(bytes,encoding) converts a numeric vector of bytes using the specified encoding scheme.

    example

    Examples

    collapse all

    Convert a vector of bytes to Unicode characters using the default encoding scheme.

    bytes = [104 101 108 108 111];
    unicodestr = native2unicode(bytes)
    unicodestr = 
    'hello'
    

    Convert an array of bytes to Unicode characters using the latin1 encoding scheme.

    bytes = [255 254 104 0 101 0 108 0 108 0 111 0];
    unicodestr = native2unicode(bytes,"UTF-16")
    unicodestr = 
    'hello'
    

    Input Arguments

    collapse all

    Bytes, specified as a numeric vector where each element must be in the range [0,255].

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Unicode encoding scheme, specified as a string scalar or character vector containing the encoding scheme name. Some example encoding schemes are: 'UTF-8', 'latin1', 'US-ASCII', or 'Shift_JIS'. This function accepts encoding schemes defined by the International Components for Unicode (ICU) libraries, for more information, see Conversion in the ICU documentation.

    Output Arguments

    collapse all

    Unicode text, returned as a character vector.

    Tips

    • The default encoding scheme might not match the encoding scheme of bytes read from a file.

    Extended Capabilities

    expand all

    Version History

    Introduced before R2006a