class MString

Jump to documentation

Manipulate strings. (OpenMaya)

public members:

MString ()
MString ( const char* charString )
MString ( const wchar_t* charString )
MString ( const char* charString, int charLength )
MString ( const wchar_t* charString, int wcharLength )
MString ( const MString & other )
~MString ()
MString & operator += ( const MString & other )
MString & operator += ( const char * other )
MString & operator += ( double other )
MString & operator += ( int other )
MString & operator += ( unsigned int other )
MString & operator += ( float other )
MString & operator = ( const MString & other )
MString & operator = ( const char * other )
MString & operator = ( double value )
bool operator == ( const MString & other ) const
bool operator == ( const char * other ) const
bool operator != ( const MString & other ) const
bool operator != ( const char * other ) const
MString operator + (const MString & other ) const
MString operator + (const char * other ) const
MString operator + ( double value ) const
MStatus set ( const char * charString )
MStatus setUTF8 ( const char *utf8String )
MStatus setWChar ( const wchar_t * wcharString )
MStatus set ( const char * charString, int charLength )
MStatus setWChar ( const wchar_t * wcharString, int wcharLength )
MStatus set ( double value )
MStatus set ( double value, int precision )
const char* asChar () const
const char* asChar (int &charLength) const
const char* asUTF8 () const
const char* asUTF8 (int &utf8Length) const
const wchar_t* asWChar () const
const wchar_t* asWChar (int & numChars ) const
unsigned int length () const
unsigned int numChars () const
void clear ()
int index (char) const
int indexW (char) const
int indexW (wchar_t) const
int indexW (const MString &) const
int rindex (char) const
int rindexW (char) const
int rindexW (wchar_t) const
int rindexW (const MString &) const
MStatus split (char, MStringArray &) const
MStatus split (wchar_t, MStringArray &) const
MString substring (int start, int end) const
MString substringW (int start, int end) const
MString & toUpperCase ()
MString & toLowerCase ()
bool isShort () const
short asShort () const
bool isInt () const
int asInt () const
bool isUnsigned () const
unsigned int asUnsigned () const
bool isFloat () const
float asFloat () const
bool isDouble () const
double asDouble () const
MString expandEnvironmentVariablesAndTilde ( MStatus * ReturnStatus = NULL ) const
MStatus format (const MString &fmt, const MStringArray & args)
MStatus format (const MString &fmt, const MString & arg1=MString::argUnused, const MString & arg2=MString::argUnused, const MString & arg3=MString::argUnused, const MString & arg4=MString::argUnused, const MString & arg5=MString::argUnused, const MString & arg6=MString::argUnused, const MString & arg7=MString::argUnused, const MString & arg8=MString::argUnused, const MString & arg9=MString::argUnused, const MString & arg10=MString::argUnused)
friend std::ostream& operator<< (std::ostream&, const MString & )
NO SCRIPT SUPPORT
friend MString operator+ (const char *, const MString & )
NO SCRIPT SUPPORT

Documentation

Methods for handling strings.
Description

The MString class implements a string class, and is used to pass all string arguments to Maya API methods.

Functions

MString:: MString ()

Description

The Class constructor. Initializes the new MString instance to the empty string.

MString:: MString ( const char* charString )

Description

Class constructor. Create a new instance of an MString and initialize it to the given null-terminated character string.

NOTE: in multibyte locales, the character buffer encoding is assumed to be the native multibyte encoding of the current locale.

Arguments

  • charString the initial string value (null-terminated)

MString:: MString ( const char* charString, int charLength )

Description

Class constructor. Create a new instance of an MString and initialize it with the character buffer passed, to the specified length. The length value is the length in bytes of the character buffer passed.

NOTE: in multibyte locales, the character buffer encoding is assumed to be the native multibyte encoding of the current locale.

Arguments

  • charString the initial string value.
  • charLength the initial string length.

MString:: MString ( const MString & other )

Description

Copy constructor. Create a new MString instance and initialize is with the same string as the given one.

Arguments

  • other the MString to copy from.

MString:: MString ( const wchar_t* wcharString )

Description

Class constructor. Create a new instance of an MString and initialize it with the null-terminated wide character string.

Arguments

  • wcharString the initial string value (null-terminated).

MString:: MString ( const wchar_t* wcharString, int wcharLength )

Description

Class constructor. Create a new instance of an MString and initialize it to the given wide character string of specified length.

The length value corresponds to the number of wide characters in the initialization string.

Arguments

  • wcharString the initial string value.
  • wcharLength the initial string length (number of characters).

MString:: ~MString ()
Description

The class destructor.

MString & MString:: operator += (const MString & other )

Description

Addition operator. The addition of 2 MStrings results in their concatenation.

MString & MString:: operator += ( const char * other )

Description

Addition operator. The addition of an MString and a C string results in their concatenation.

MString & MString:: operator += ( double other )

Description

Addition operator. The addition of an MString and a double results in their concatenation.

MString & MString:: operator += ( int other )

Description

Addition operator. The addition of an MString and an int results in their concatenation.

MString & MString:: operator += ( unsigned int other )

Description

Addition operator. The addition of an MString and an unsigned int results in their concatenation.

MString & MString:: operator += ( float other )

Description

Addition operator. The addition of an MString and a float results in their concatenation.

MString MString:: operator + (const MString & other ) const

Description

Addition operator. The addition of two MStrings results in their concatenation.

MString MString:: operator + ( const char * other ) const

Description

Addition operator. The addition of an MString and a C string results in their concatenation.

MString MString:: operator + ( double value ) const

Description

Addition operator. The addition of an MString and a number results in their concatenation.

MString operator + (const char *first, const MString & second )

Description

Addition operator. The addition of a C string with an MString results in their concatenation.

MString & MString:: operator = (const MString & other )

Description

Assignment operator. Allows assignment between MString instances.

MString & MString:: operator = (const char * other )

Description

Assignment operator. Allows assignment of a C string to this MString.

MString & MString:: operator = ( double value )

Description

Assignment operator. Allows assignment of a number to this MString.

bool MString:: operator == (const MString & other ) const

Description

Equality operator. Allows 2 MStrings to be compared to see if they contain identical strings.

bool MString:: operator == (const char * other ) const

Description

Equality operator. Allows an MString and a C string to be compared to see if they contain identical strings.

bool MString:: operator != (const MString & other ) const
Description Inequality operator. Allows two MStrings to be compared to see if they differ.

bool MString:: operator != (const char * other ) const
Description Inequality operator. Allows an MString to be compared with a c string to see if they differ.

MStatus MString:: set ( const char * charString )

Description

Set the value of the string in this MString instance. to the value of the null-terminated character string.

NOTE: in multibyte locales, the character buffer encoding is assumed to be the native multibyte encoding of the current locale.

Arguments

  • charString new string value (null-terminated).

Return Value

  • MS::kSuccess for success, otherwise MS::kFailure

MStatus MString:: set ( const char * charString, int charLength )

Description

Set the value of the string in this MString instance to the value of the character buffer passed.

The length value is the length in bytes of the character buffer.

NOTE: in multibyte locales, the character buffer encoding is assumed to be the native multibyte encoding of the current locale.

Arguments

  • charString new string value.
  • charLength new string length.

Return Value

  • MS::kSuccess for success, otherwise MS::kFailure

MStatus MString:: set ( double value )

Description

Set the value of the string in this MString instance. The numeric value will be converted to a character string.

Arguments

  • value new number.

Return Value

  • MS::kSuccess for success, otherwise MS::kFailure

MStatus MString:: set ( double value, int precision )

Description

Set the value of the string in this MString instance, with the given precision. The numeric value will be converted to a character string.

Arguments

  • value new number.
  • precision the precision (number of decimal places).

Return Value

  • MS::kSuccess for success, otherwise MS::kFailure

MStatus MString:: setUTF8 ( const char * utf8String )

Description

Set the value of the string in this MString instance using a null-terminated utf-8 encoded character string.

Note: conversion errors may occur if the multibyte encoding of the current locale cannot represent the utf-8 characters in the assignment string.

Arguments

  • utf8String null-terminated utf-8 character string buffer.

Return Value

  • MS::kSuccess for success, otherwise MS::kFailure

MStatus MString:: setWChar ( const wchar_t * wcharString )

Description

Set the value of the string in this MString instance using a null-terminated wide character string.

Arguments

  • wcharString null-terminated wide character string buffer.

Return Value

  • MS::kSuccess for success, otherwise MS::kFailure

MStatus MString:: setWChar ( const wchar_t * wcharString, int wcharLength )

Description

Set the value of the string in this MString instance using a wide string and its length.

The length value corresponds to the number of wide characters in the input string.

Arguments

  • charString new wide character string value.
  • charLength new string length (number of wide characters)

Return Value

  • MS::kSuccess for success, otherwise MS::kFailure

MStatus MString:: format ( const MString &fmt, const MStringArray &args )

Description

Format the string value using a format specifier and an array of positional arguments.

A maximum of 10 arguments may be specified in the array passed. The number of arguments must match exactly the number of arguments expected by the format statement.

All arguments are passed as MStrings (any numeric data for example must already be formatted by the caller into an MString).

Format specifiers determine the relative position and ordering of arguments in the string using specifiers of the form: ^1s ^2s ^3s etc. See also the mel format command.

Arguments

  • fmt format string (up to 10 positional argument specifiers)
  • args array of arguments to be positioned in the format string

Return Value

  • MS::kSuccess for success, otherwise MS::kFailure

MStatus MString:: format ( const MString &fmt, const MString &arg1, const MString &arg2, const MString &arg3, const MString &arg4, const MString &arg5, const MString &arg6, const MString &arg7, const MString &arg8, const MString &arg9, const MString &arg10 )

Description

Format the string value using a format specifier and positional arguments.

A maximum of 10 argument strings may be passed in the argument list. This routine accepts a variable number of arguments in the argument list. Unused arguments should not be passed. (i.e. if 3 arguments are required by the format statement, exactly 3 arguments should be passed when calling MString::format).

All arguments are passed as MStrings (any numeric data for example must already be converted by the caller to an MString).

Format specifiers determine the relative position and ordering of arguments in the string using specifiers of the form: ^1s ^2s ^3s etc. See also the mel format command for more information.

Arguments

  • fmt format string (up to 10 positional arguments)
  • arg1-arg10 arguments to be positioned in the format string

Return Value

  • MS::kSuccess for success, otherwise MS::kFailure

const char * MString:: asChar () const
Description

Return the current string in this MString instance as a C++ char* pointer. The string will be returned as a null-terminated buffer of type char.

In a localized environment, the string will contain a buffer of multibyte characters in the locale's native encoding.

The length of this representation of the string can be obtained by calling the alternate version of this method that returns the string length, or by calling MString::length().

NOTE: The string should be duplicated if it will be re-used.

Return Value

  • the char* pointer to the string in this MString instance.

const char * MString:: asChar (int &charLength) const
Description

Return the current string in this MString instance as a C++ char* pointer. The string will be returned as a null-terminated buffer of type char.

In a localized environment, the string will contain a buffer of multibyte characters in the locale's native encoding.

The argument passed will be used to return the length of the character buffer returned in bytes (excluding the trailing null).

NOTE: the length value corresponds to the string's character length in bytes, which can differ from the number of characters in the string when running in a localized environment.

NOTE: The string should be duplicated if it will be re-used.

Arguments

  • charLength value which will be set to the length of the character buffer returned

Return Value

  • the char* pointer to the string in this MString instance.

const char * MString:: asUTF8 () const
Description

Return the current string in this MString instance as a C++ char* pointer to a null-terminated utf-8 encoded string.

The length of this buffer can be obtained by calling the alternate form of MString::asUTF8 which returns the length value.

NOTE: The string should be duplicated if it will be re-used.

Return Value

  • the char* pointer to the utf-8 encoded string

const char * MString:: asUTF8 (int &utf8Length) const
Description

Return the current string in this MString instance as a C++ char* pointer to a null-terminated utf-8 encoded string. The integer argument passed will be used to return the length of this buffer (in bytes) excluding the trailing null.

NOTE: The string should be duplicated if it will be re-used.

Arguments

  • charLength value which will be set to the length of the character buffer returned

Return Value

  • the char* pointer to the utf-8 encoded string

const wchar_t * MString:: asWChar () const
Description

Return the current string in this MString instance as pointer to a null terminated wide character (wchar_t) buffer. The number of characters in this buffer will be equivalent to MString::numChars, or can be determined by using the alternate form of MString::awWChar which returns the buffer length.

NOTE: wchar_t types are not portable between platforms and are not recommended for persistent data. A portable multibyte format such as UTF-8 is recommended for file I/O.

NOTE: The string should be duplicated if it will be re-used.

Return Value

  • the wchar_t* pointer to the string in this MString instance.

const wchar_t * MString:: asWChar (int &wcharLength) const
Description

Return the current string in this MString instance as pointer to a null terminated wide character (wchar_t) buffer.

The length value returned corresponds to the number of wide characters in the buffer returned (excluding the trailing null).

NOTE: wchar_t types are not portable between platforms and are not recommended for persistent data. A portable multibyte format such as UTF-8 is recommended for file I/O.

NOTE: The string should be duplicated if it will be re-used.

Arguments

  • wcharLength number of wide characters in buffer returned

Return Value

  • the wchar_t* pointer to the string in this MString instance.

unsigned int MString:: length () const
Description

Returns the length of the string buffer in this MString instance.

This value corresponds to the length, in bytes, of the charcter buffer returned from the MString::asChar method, excluding the trailing null.

NOTE: When running in a localized (multibyte) environment, the MString::asChar method will return a multibyte buffer, in which the number of characters in the string may not correspond to the number of bytes in the multibyte representation. The use of the MString::numChars method is recommended in place of MString::length for determining the number of individual characters in the string.

Return Value

  • unsigned integer value giving the string's character buffer length.

unsigned int MString:: numChars () const
Description

Returns the number of characters in the MString instance.

NOTE: this value corresponds to the number of actual characters in the string, not its character buffer length. It is suitable for localized environments as it correctly handles multibyte characters.

Return Value

  • unsigned integer value giving the number of characters in the string.

void MString:: clear ()

Description

Clears the contents of this MString instance and sets it value to the empty string.

int MString:: index (char searchChar) const

Description

Returns the position of the first occurance of the character searchChar in the string or -1 if the character is not found.

The position value returned from index is a byte-based charcter position corresponding to the location in the asChar() form of the string.

NOTE: since this version of index works on the char form of the string it is not reliable within localized (multibyte) environments as the positions returned may not correctly match character boundaries in the multibyte buffer. Use of MString::indexW is recommended instead.

Arguments

  • searchChar the character to search for

Return Value

  • the position of searchChar in the string, or -1 if the searchChar is not found

int MString:: rindex (char searchChar) const

Description

Returns the position of the last occurance of the character searchChar in the string or -1 if the character is not found.

The position value returned from rindex is a byte-based character position corresponding to the location in the asChar() form of the string.

NOTE: since this version of rindex works on the char form of the string it is not reliable within localized (multibyte) environments as the positions returned may not correctly match character boundaries in the multibyte buffer. Use of MString::rindexW is recommended instead.

Arguments

  • searchChar the character to search for

Return Value

  • the position of searchChar in the string, or -1 if the searchChar is not found

int MString:: indexW (char searchChar) const

Description

Returns the position of the first occurance of the character searchChar in the string or -1 if the character is not found.

The position value returned from indexW is a character-based position and correctly handles strings in localized (multibyte) environments. Use of MString::indexW over MString::index is recommended.

Arguments

  • searchChar the character to search for

Return Value

  • the position of searchChar in the string, or -1 if the searchChar is not found

int MString:: indexW (wchar_t searchChar) const

Description

Returns the position of the first occurance of the wide character searchChar in the string or -1 if the character is not found.

The position value returned from indexW is a character-based position and correctly handles strings in localized (multibyte) environments. Use of MString::indexW over MString::index is recommended.

Arguments

  • searchChar the wide character to search for

Return Value

  • the position of searchChar in the string, or -1 if the searchChar is not found

int MString:: indexW (const MString &searchStr) const

Description

Returns the position of the first occurance of the searchString in the string or -1 if it is not found.

The position value returned from indexW is a character-based position and correctly handles strings in localized (multibyte) environments.

Arguments

  • searchChar the string to search for

Return Value

  • the starting position of searchString in the string, or -1 if it is not found

int MString:: rindexW (char searchChar) const

Description

Returns the position of the last occurance of the character searchChar in the string or -1 if the character is not found.

The position value returned from rindexW is a character-based position and correctly handles strings in localized (multibyte) environments. Use of MString::indexW over MString::index is recommended.

Arguments

  • searchChar the character to search for

Return Value

  • the position of searchChar in the string, or -1 if the searchChar is not found

int MString:: rindexW (wchar_t searchChar) const

Description

Returns the position of the last occurance of the wide character searchChar in the string or -1 if the character is not found.

The position value returned from rindexW is a character-based position and correctly handles strings in localized (multibyte) environments. Use of MString::indexW over MString::index is recommended.

Arguments

  • searchChar the character to search for

Return Value

  • the position of searchChar in the string, or -1 if the searchChar is not found

int MString:: rindexW (const MString &searchStr) const

Description

Returns the position of the last occurance of the searchString in the string or -1 if it is not found.

The position value returned from indexW is a character-based position and correctly handles strings in localized (multibyte) environments.

Arguments

  • searchChar the string to search for

Return Value

  • the position of searchString in the string, or -1 if it is not found

MStatus MString:: split (char theChar, MStringArray & theArray) const

Description

Split the string up at each occurrence of theChar and place the separate strings into theArray. The current string instance is not modified.

NOTE: for compatibilty in localized environments an alternate form of of MString::split that accept wide-characters is also provided.

Arguments

  • theChar the character on which to split
  • theArray the MStringArray to populate

Return Value

  • MS::kSuccess on success, and MS::kFailure on failure

MStatus MString:: split (wchar_t theWChar, MStringArray & theArray) const

Description

Split the string up at each occurrence of the given wide character and place the separate strings into theArray. The current string instance is not modified.

NOTE: this method accepts a wide character type and is the preferred format for compatibility in localized environments.

Arguments

  • theChar the character on which to split
  • theArray the MStringArray to populate

Return Value

  • MS::kSuccess on success, and MS::kFailure on failure

MString MString:: substring (int start, int end) const

Description

Return a new MString instance that contains the characters from start to end inclusive.

Start and end are byte-based positions corresponding to the asChar() form of the string.

NOTE: since this version of substring works on the char form of the string it is not compatible with localized (multibyte) environments as the positions specified may not correctly match character boundaries in the multibyte buffer. Use of MString::substringW is recommended instead.

Arguments

  • start the index of the first character to copy
  • end the index of the last character to copy

Return Value

  • an MString containing the substring.

MString MString:: substringW (int start, int end) const

Description

Return a new MString instance that contains the characters from start to end inclusive.

Start and end are character-based positions and correctly deal with multibyte strings in localized environments.

NOTE: use of MString::substringW over MString::substring is recommended

Arguments

  • start the index of the first character to copy
  • end the index of the last character to copy

Return Value

  • an MString containing the substring.

MString & MString:: toUpperCase ()

Description

Modify the current instance of the string replacing all lower case characters in the corresponding upper case characters.

Return Value

  • a reference to the current, modified MString instance

MString & MString:: toLowerCase ()

Description

Modify the current instance of the string replacing all lower case characters in the corresponding upper case characters.

Return Value

  • a reference to the current, modified MString instance

bool MString:: isShort () const

Description

Returns true if the string represents a valid short, and false otherwise.

Return Value

  • true or false

short MString:: asShort () const

Description

Returns the value of the string in this MString instance converted to a short. If the string does contain a valid string representation of a short, then the results of this operation are undefined.

Return Value

  • the value of the current string converted to a short.

bool MString:: isInt () const

Description

Returns true if the string represents a valid int, and false otherwise.

Return Value

  • true or false

int MString:: asInt () const

Description

Returns the value of the string in this MString instance converted to an integer. If the string does contain a valid string representation of an integer, then the results of this operation are undefined.

Return Value

  • the value of the current string converted to an integer.

bool MString:: isUnsigned () const

Description

Returns true if the string represents a valid unsigned int, and false otherwise.

Return Value

  • true or false

unsigned int MString:: asUnsigned () const

Description

Returns the value of the string in this MString instance converted to an unsigned integer. If the string does contain a valid string representation of an unsigned integer, then the results of this operation are undefined.

Return Value

  • the value of the current string converted to an integer.

bool MString:: isFloat () const

Description

Returns true if the string represents a valid float, and false otherwise.

Return Value

  • true or false

float MString:: asFloat () const

Description

Returns the value of the string in this MString instance converted to a float. If the string does contain a valid string representation of a float, then the results of this operation are undefined.

Return Value

  • the value of the current string converted to a float.

bool MString:: isDouble () const

Description

Returns true if the string represents a valid double, and false otherwise.

Return Value

  • true or false

double MString:: asDouble () const

Description

Returns the value of the string in this MString instance converted to a double. If the string does contain a valid string representation of a double, then the results of this operation are undefined.

Return Value

  • the value of the current string converted to a double.

MString MString:: expandEnvironmentVariablesAndTilde ( MStatus * ReturnStatus ) const

Description

Returns a new string constructed by duplicating the current string with all environment variables expanded (and on UNIX, tilde characaters ("~") are also expanded. Environment variables may be of the form

$ENV_VAR or
	$
{ENV_VAR}. On Windows, %ENV_VAR, %ENV_VAR% and %{ENV_VAR}% are also accepted. If no environment variable in the system matches that given, the unexpanded variable is copied verbatim into the result string. On UNIX, any tilde characters ("~") will also be expanded according to the standard UNIX convention. If the user name associated with a tilde is undefined, the tilde and name which follows it are copied verbatim into the result string. Notes (1) when any error occurs, processing continues such that all subsequent environment variable and tilde occurences are processed and the resulting string can be displayed to the user to help diagnose the undefined entities (2) escape sequences using backslash characters are not supported.

Arguments

  • MStatus *ReturnStatus status of the operation. MS::kSuccess for success, MS::kNotFound if one or more environment variables or tildes failed to expand.

Return Value

  • returns a new string containing the value of the original string with environment variable (and tilde characters on UNIX) which were defined expanded. All undefined environment variables and tildes are copied into the result string unexpanded.

std::ostream& operator<< (std::ostream& s, const MString & str )

Description

Print the contents of the given MString on the given ostream.

Arguments

  • s the ostream to print to
  • str the MString whose value is to be printed

Return Value

  • the ostream reference, s, provided as the first parameter.

This class has no child classes.


Autodesk® Maya® 2008 © 1997-2007 Autodesk, Inc. All rights reserved. doc++ Copyright