Main Content

mwString

String class used by the mwArray API to pass string data as output from certain methods

Description

The mwString class is a simple string class used by the mwArray API to pass string data as output from certain methods.

Required Headers

  • mclcppclass.h

  • mclmcrrt.h

Tip

MATLAB® Compiler SDK™ automatically includes these header files in the header file generated for your MATLAB functions.

Constructors

mwString()

Description

Create an empty string.

mwString(char* str)

Description

Create a new string and initialize the string’s data with the supplied char buffer.

Arguments
char* strNull terminated character buffer

mwString(mwString& str)

Description

Create a new string and initialize the string’s data with the contents of the supplied string.

Arguments
mwString& strInitialized mwString instance

Methods

int Length() const

Description

Return the number of characters in string.

Example
mwString str("This is a string");
int len = str.Length();

Operators

operator const char* () const

Description

Return a pointer to internal buffer of string.

Example
mwString str("This is a string");
const char* pstr = (const char*)str;

mwString& operator=(const mwString& str)

Description

Copy the contents of one string into a new string.

Arguments
mwString& strInitialized mwString instance to copy
Example
mwString str("This is a string");
mwString new_str = str;

mwString& operator=(const char* str)

Description

Copy the contents of a null terminated character buffer into a new string.

Arguments
char* strNull terminated character buffer to copy
Example
const char* pstr = "This is a string";
mwString str = pstr;

bool operator==(const mwString& str) const

Description

Test two mwString instances for equality. If the characters in the string are the same, the instances are equal.

Arguments
mwString& strInitialized mwString instance
Example
mwString str("This is a string");
mwString str2("This is another string");
bool ret = (str == str2);

bool operator!=(const mwString& str) const

Description

Test two mwString instances for inequality. If the characters in the string are not the same, the instances are inequal.

Arguments
mwString& strInitialized mwString instance
Example
mwString str("This is a string");
mwString str2("This is another string");
bool ret = (str != str2);

bool operator<(const mwString& str) const

Description

Compare two strings and return true if the first string is lexicographically less than the second string.

Arguments
mwString& strInitialized mwString instance
Example
mwString str("This is a string");
mwString str2("This is another string");
bool ret = (str < str2);

bool operator<=(const mwString& str) const

Description

Compare two strings and return true if the first string is lexicographically less than or equal to the second string.

Arguments
mwString& strInitialized mwString instance
Example
mwString str("This is a string");
mwString str2("This is another string");
bool ret = (str <= str2);

bool operator>(const mwString& str) const

Description

Compare two strings and return true if the first string is lexicographically greater than the second string.

Arguments
mwString& strInitialized mwString instance
Example
mwString str("This is a string");
mwString str2("This is another string");
bool ret = (str > str2);

bool operator>=(const mwString& str) const

Description

Compare two strings and return true if the first string is lexicographically greater than or equal to the second string.

Arguments
mwString& strInitialized mwString instance
Example
mwString str("This is a string");
mwString str2("This is another string");
bool ret = (str >= str2);

friend std::ostream& operator<<(std::ostream& os, const mwString& str)

Description

Copy contents of input string to specified ostream.

Arguments
std::ostream& osInitialized ostream instance to copy string into
mwString& strInitialized mwString instance to copy
Example
#include <ostream>
mwString str("This is a string");
std::cout << str << std::endl;
Introduced in R2013b