Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

unicode2native

Convert Unicode character representation to numeric bytes

Syntax

bytes = unicode2native(unicodestr)
bytes = unicode2native(unicodestr,encoding)

Description

bytes = unicode2native(unicodestr) converts a char vector of Unicode® character representations, unicodestr, to the user default encoding, and returns the bytes as a uint8 vector, bytes. Output vector bytes has the same general array shape as the unicodestr input. You can save the output of unicode2native to a file using the fwrite function.

bytes = unicode2native(unicodestr,encoding) converts unicodestr to the character encoding scheme specified by the character vector encoding. encoding must have no characters ('') or must be a name or alias for an encoding scheme. Some examples are 'UTF-8', 'latin1', 'US-ASCII', and 'Shift_JIS'. If encoding is unspecified or has no characters (''), the default encoding scheme is used.

Examples

This example begins with two character vectors containing Unicode character representations. It assumes that str1 contains text in a Western European language and that str2 contains Japanese text. The example writes both character vectors into the same file, using the ISO-8859-1 character encoding scheme for the first character vector and the Shift-JIS encoding scheme for the second character vector. The example uses unicode2native to convert str1 and str2 to the appropriate encoding schemes.

fid = fopen('mixed.txt', 'w');
bytes1 = unicode2native(str1, 'ISO-8859-1');
fwrite(fid, bytes1, 'uint8');
bytes2 = unicode2native(str2, 'Shift_JIS');
fwrite(fid, bytes2, 'uint8');
fclose(fid);

Introduced before R2006a

Was this topic helpful?