Main Content

matlab::engine::convertUTF8StringToUTF16String

Convert UTF-8 string to UTF-16 string

Description

std::basic_string<char16_t> convertUTF8StringToUTF16String(const std::string& utf8string)

Convert a UTF-8 string to a UTF-16 string. Use this function to convert ASCII strings to matlab::engine::String strings, which are used by MATLAB® C++ Engine functions.

Include

Namespace:

matlab::engine
IncludeMatlabEngine.hpp

Parameters

const std::string& utf8string

A UTF-8 string

Return Value

std::basic_string<char16_t>

A UTF-16 string

Exceptions

matlab::engine::OutofMemoryException

The function failed to allocate memory.

matlab::engine::TypeConversionException

The input type cannot be converted to std::basic_string<char16_t>.

Examples

Convert String

Convert a UTF-8 string to a matlab::engine::String (UTF-16 string).

std::u16string matlabStatement = convertUTF8StringToUTF16String("sRoot = sqrt(12.7);");

Alternative Conversion

If you are using a C++ compiler that supports the use of the "u" prefix to create UTF-16 encoded string literals, you can use this approach to create inputs for engine functions. For example, this code defines a variable that contains a MATLAB statement as a UTF-16 string.

std::u16string matlabStatement = u"sRoot = sqrt(12.7);";

For an up-to-date list of supported compilers, see the Supported and Compatible Compilers website.

Version History

Introduced in R2017b