MATLAB Function Reference |
Convert Unicode characters to numeric bytes
Syntax
Description
bytes = unicode2native(unicodestr)
takes a char
vector of Unicode characters, unicodestr
, converts it to the native character set of the machine, 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, charset)
converts the Unicode characters to characters from the character set charset
instead of the native character set.
Examples
This example reads and displays some Japanese text. The command disp(str)
requires that str
consist entirely of Unicode characters to display correctly. The example calls fwrite
to save the text to file 'japanese_out.txt'
. To write this file using the original character set, call unicode2native
first to convert the Unicode string back to 'Shift_JIS'
:
fid = fopen('japanese_in.txt'); b = fread(fid, '*char')'; fclose(fid); str = native2unicode(b, 'Shift_JIS'); disp(str); b = unicode2native(str, 'Shift_JIS'); fid = fopen('japanese_out.txt', 'w'); fwrite(fid,b); fclose(fid);
Common names for charset
are 'US-ASCII'
, and 'Shift_JIS'
. In this example, the charset
string must use 'US-ASCII'
characters. Letter case does not matter. For the preferred list of names for charset
consult the Web site http://www.iana.org/assignments/character-sets.
See Also
undocheckout | union |
© 1994-2005 The MathWorks, Inc.