Class CStr

3DS Max Plug-In SDK

Class CStr

See Also: Class WStr, Character Strings.

class CStr

Description:

A simple character string class. This is the standard character string class used in MAX. Methods and operators are provided for calculating lengths, concatenation, substring operations, character searching, case conversion, comparison, and formatted writing.

This class automatically allocates the proper amount of space for the string. This is very handy in the case of internationalization / localization. For example, if you code something like:

TSTR myString = GetString(IDS_STRING_ID);

then myString's constructor will allocate enough space to store the resource string no matter how long it is. This is much better than doing the following:

TCHAR myString[64];

_tcscpy(myString, GetString(IDS_STRING_ID));

because the resource string may turn out to be much longer than 64 bytes once it's translated to German or French (or whatever).

As another example, if you have the following code:

TSTR str1 = _T("This is string1.");

TSTR str2 = _T("This is string2.");

Then

TSTR concatStr = str1 + str2;

will again yield a (concatenated) string will enough space to hold the concatenated contents of str1 and str2, automatically.

All methods are implemented by the system.

Methods:

Prototype:

CStr();

Remarks:

Constructor. The string is set to NULL.

Prototype:

CStr(const char *cs);

Remarks:

Constructor. The string is initialized to the string passed.

Prototype:

CStr(const wchar_t *wcstr);

Remarks:

Constructor. The string is initialized to the string passed.

Prototype:

CStr(const CStr& ws);

Remarks:

Constructor. The string is initialized to the string passed.

Prototype:

~CStr()

Remarks:

Destructor. The string is deleted.

Prototype:

char *data();

Remarks:

Returns a pointer to the string. If the string is NULL, 0 is returned.

Prototype:

const char *data() const;

Remarks:

This method is available in release 3.0 and later only.

Returns a pointer to the string. If the string is NULL, 0 is returned.

Prototype:

operator char *();

Remarks:

Returns a pointer to the string. If the string is NULL, 0 is returned.

Prototype:

void Resize(int nchars);

Remarks:

Reallocates the string to contain nchars characters. If the string is enlarged it is padded with blanks.

Parameters:

int nchars

Specifies the new number of characters for the string.

Prototype:

int Length() const;

Remarks:

Returns the number of characters in the string.

Prototype:

int length() const;

Remarks:

Returns the number of characters in the string.

Prototype:

BOOL isNull();

Remarks:

Returns TRUE if the string length is 0; otherwise FALSE.

Prototype:

CStr & operator=(const CStr& cs);

Remarks:

Assignment operator.

Prototype:

CStr & operator=(const wchar_t *wcstr);

Remarks:

Assignment operator.

Prototype:

CStr & operator=(const char *cs);

Remarks:

Assignment operator. In release 3.0 and later this method check for self-assignment.

Prototype:

CStr operator+(const CStr& cs) const;

Remarks:

Concatenation operator. Returns a new string that is this string with string cs appended.

Prototype:

CStr& operator+=(const CStr& cs);

Remarks:

Concatenation. Returns this string with cs appended.

Prototype:

CStr& Append(const CStr& cs);

Remarks:

Concatenation. Returns this string with cs appended.

Prototype:

CStr& append(const CStr& cs);

Remarks:

Concatenation. Returns this string with cs appended to the end.

Prototype:

CStr& remove(int pos);

Remarks:

Returns this string with all characters from pos to the end removed.

Parameters:

int pos

Specifies the last position in the string.

Prototype:

CStr& remove(int pos, int N);

Remarks:

Returns this string with N characters removed from pos to the end.

Parameters:

int pos

Specifies the position to begin removing characters.

int N

Specifies the number of characters to remove.

Prototype:

CStr Substr(int start, int nchars) const;

Remarks:

Returns a substring of this string, beginning at position start, of length nchars.

Prototype:

char& operator[](int i)

Remarks:

Returns a substring of this string beginning at position i.

Prototype:

const char& operator[](int i) const;

Remarks:

This method is available in release 3.0 and later only.

Returns a substring of this string beginning at position i.

Prototype:

int first(char c) const;

Remarks:

Returns the index of the first occurrence of character c in this string. Returns -1 if not found.

Prototype:

int last(char c) const;

Remarks:

Returns the index of the last occurrence of character c in this string. Returns -1 if not found.

Prototype:

int operator==(const CStr &cs) const;

Remarks:

Equality operator.

Return Value:

Nonzero if the strings are equal; otherwise 0.

Prototype:

int operator<(const CStr &cs) const;

Remarks:

Returns nonzero if this string is less than cs; otherwise 0.

Prototype:

int operator<=(const CStr &ws) const;

Remarks:

Returns nonzero if this string is less than or equal to ws; otherwise 0.

Prototype:

int operator>(const CStr &ws) const;

Remarks:

Returns nonzero if this string is greater than ws; otherwise 0.

Prototype:

int operator>=(const CStr &ws) const;

Remarks:

Returns nonzero if this string is greater than or equal to ws; otherwise 0.

Prototype:

void toUpper();

Remarks:

Converts all character of this string to uppercase.

Prototype:

void toLower();

Remarks:

Converts all character of this string to lowercase.

Prototype:

int printf(const char *format, ...);

Remarks:

Formatted output to this string. The internal buffer size for the output string is 512 bytes.

Return Value:

The number of character output or EOF on error.

Sample Code:

TSTR buf;

buf.printf(_T("Rendering In Progress: Frame %d"), curFrame);