string::SetAt

Description

Overwrite a single character specified by an index number. SetAt will not enlarge the string if the index exceeds the bounds of the existing string.


Set a unicode character in the form of a string at the specified position.

Syntax

void SetAt( int nIndex, char ch )

void SetAt( int nIndex, LPCTSTR pstr )

Parameters

nIndex
[input]Zero-based index of the character in the string object. The nIndex parameter must be greater than or equal to 0 and less than the value returned by GetLength.
ch
[input]The character to insert.

nIndex
[input] position in string, see Remark
pstr
[input] unicode character pointer

Return

None.

Examples

EX1

void string_SetAt_ex1()
{
        string str( "abcdef" );
        str.SetAt(2,'z');
        out_str(str);//"abzdef"
        
        str.SetAt(8,'z');//if the index exceeds the length of the string,the string stays unchanged
        out_str(str);//"abzdef"
}


EX2

void SetAt_ex2(string str1)
{
        string str2 = "#";
        string str3 = str1;
        str3.SetAt(0, str2);
        out_str(str3);
}

Remark

Index can be either byte offset, or character offset, dependent on the system variable @SCOC, which is typicalled controlled by the macro ENABLE_STR_LENGTH_USE_CHAR_COUNT

See Also

string::GetAt

Header to Include

origin.h