www.gusucode.com > external 工具箱matlab源码程序 > external/interfaces/webservices/http/+matlab/+net/+internal/getCharsetFromData.m
function charset = getCharsetFromData(data) % Heuristically try to determine the minimal charset needed to convert the string % data to bytes. All we can do without knowing the file type is choose between % us-ascii if all characters are 7 bits, or utf-8 otherwise. % % data may be a char vector, cellstr, or string vector % Copyright 2015-2016 The MathWorks, Inc. if iscellstr(data) || (isstring(data) && ~isscalar(data)) data = strjoin(data,''); % join cellstr or string array end % data is now a single string or a char array of some dimension if all(char(data) < 128) charset = 'us-ascii'; else charset = 'utf-8'; end end