Change individual character

Web Site  Methods

 
Str::SetAt
 
void SetAt (CPOS pos, STRCHAR value)

This method will change a single character at the specified 0-based position to the new value. The position must be within the existing boundaries of the string (i.e. must be less than the string's length), otherwise an exception will be thrown (error condition).

Example: transpose a string to form the first few alphabet letters

   Str s = _T("0123456");
for (int i=0; i<s.GetLength(); i++)
s.SetAt(i, 'A' + (s[i] - '0'));
 

See also: Basic operations