Main Content

matlab::data::CharArray

C++ class to access MATLAB character arrays

Description

Use CharArray objects to work with MATLAB® character arrays. To create a CharArray, call createCharArray in the ArrayFactory class.

Class Details

Namespace:

matlab::data

Base class:

TypedArray<char16_t>

Include:

CharArray.hpp

Constructors

Copy Constructors

CharArray(const CharArray& rhs)

CharArray(const Array& rhs)

Description

Creates a shared data copy of a CharArray object.

Parameters

const CharArray& rhs

Value to copy.

const Array& rhs

Value specified as ArrayType::CHAR object.

Throws

matlab::data::InvalidArrayTypeException

Type of input Array is not ArrayType::CHAR.

Examples
#include "MatlabDataArray.hpp"

int main() {
    using namespace matlab::data;
    ArrayFactory factory;
    CharArray A = factory.createCharArray("This is a char array");
    CharArray B(A);
    return 0;
}
Related Topics

createCharArray

Copy Assignment Operators

CharArray& operator=(const CharArray& rhs)

CharArray& operator=(const Array& rhs)

Description

Assigns a shared data copy to a CharArray object.

Parameters

const CharArray& rhs

Value to copy.

const Array& rhs

Value specified as ArrayType::CHAR object.

Returns

CharArray&

Updated instance.

Throws

matlab::data::InvalidArrayTypeException

Type of input Array is not ArrayType::CHAR.

Examples
#include "MatlabDataArray.hpp"

int main() {
    using namespace matlab::data;
    ArrayFactory factory;
    CharArray A = factory.createCharArray("This is a char array");
    CharArray C = factory.createCharArray("");

    // Arrays A and C refer to the same data.
    C = A;

    return 0;
}

Move Constructors

CharArray(CharArray&& rhs)

CharArray(Array&& rhs)

Description

Moves contents of a CharArray object to a new instance.

Parameters

CharArray&& rhs

Value to move.

Array&& rhs

Value specified as ArrayType::CHAR object.

Throws

matlab::data::InvalidArrayTypeException

Type of input Array is not ArrayType::CHAR.

Examples
#include "MatlabDataArray.hpp"

int main() {
    using namespace matlab::data;
    ArrayFactory factory;
    CharArray A = factory.createCharArray("This is a char array");

    // Move constructor - Creates B, copies data from A. A not valid.
    CharArray B(std::move(A));

    return 0;
}

Move Assignment Operators

CharArray& operator=(CharArray&& rhs)

CharArray& operator=(Array&& rhs)

Description

Assigns the input to this CharArray object.

Parameters

CharArray&& rhs

Value to move.

Array&& rhs

Value specified as ArrayType::CHAR object.

Returns

CharArray&

Updated instance.

Throws

matlab::data::InvalidArrayTypeException

Type of input Array is not ArrayType::CHAR.

Examples
#include "MatlabDataArray.hpp"

int main() {
    using namespace matlab::data;
    ArrayFactory factory;
    CharArray A = factory.createCharArray("This is a char array");

    // Move assignment - Data from A moved to C. A no longer valid.
    CharArray C = factory.createCharArray("");
    C = std::move(A);

    return 0;
}

Member Functions

toUTF16

String toUTF16() const
Returns

matlab::data::String

Contents of CharArray as matlab::data::String.

Throws

None

toAscii

std::string toAscii() const
Returns

std::string

Contents of CharArray as ASCII string.

Throws

matlab::data::NonAsciiCharInRequestedAsciiOutputException

Data contains non-ASCII characters.

Examples
#include "MatlabDataArray.hpp"

int main()
{
	using namespace matlab::data;
	ArrayFactory f;
	auto arr = f.createCharArray("helloworld");
	std::string s = arr.toAscii();

	return 0;
}

Version History

Introduced in R2017b