Documentation

unicode2native

ConvertUnicodecharacter representation to numeric bytes

Syntax

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

Description

bytes = unicode2native(unicodestr)将输入转换为Unicode®character representation,unicodestr, to the user default encoding, and returns the bytes as auint8vector,bytes. Output vectorbyteshas the same general array shape as theunicodestrinput. You can save the output ofunicode2nativeto a file using thefwritefunction.unicodestrcan be a character vector or a string scalar.

bytes = unicode2native(unicodestr,encoding)convertsunicodestrto the character encoding scheme specified byencoding. The input argumentencodingmust 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'. Ifencodingis unspecified or has no characters (''), the default encoding scheme is used.encodingcan be a character vector or a string scalar.

Examples

This example begins with two character vectors containing Unicode character representations. It assumes thatstr1contains text in a Western European language and thatstr2contains 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 usesunicode2nativeto convertstr1andstr2to 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);

See Also

Introduced before R2006a

Was this topic helpful?