Contenuto principale

unicode2native

Convert Unicode characters to numeric bytes

    Description

    bytes = unicode2native(unicodestr) converts Unicode® characters to their corresponding byte values using the default encoding scheme.

    You can save the output of unicode2native to a file using the fwrite function.

    example

    bytes = unicode2native(unicodestr,encoding) converts Unicode characters using the specified encoding scheme.

    example

    Examples

    collapse all

    Convert a string to bytes using the default native encoding scheme.

    unicodestr = "hello";
    bytes = unicode2native(unicodestr)
    bytes = 1×5 uint8 row vector
    
       104   101   108   108   111
    
    

    Convert a string to bytes using the latin1 encoding scheme.

    unicodestr = "hello";
    bytes = unicode2native(unicodestr,"UTF-16")
    bytes = 1×12 uint8 row vector
    
       255   254   104     0   101     0   108     0   108     0   111     0
    
    

    Input Arguments

    collapse all

    Unicode text, specified as a string scalar or character vector.

    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

    Bytes, returned as a uint8 vector where each element is in the range [0,255].

    Data Types: uint8

    Tips

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

    Extended Capabilities

    expand all

    Version History

    Introduced before R2006a