Access individual character |
![]() |
|
|
|
|
|
Returns the first character in the string. If the string is empty, will return 0 (the null character).
|
|
|
|
|
Returns the last character in the string. If the string is empty, will throw an exception (error condition).
|
|
|
|
|
The GetAt() method, and its equivalent indexing operator, will retrieve a single character from the string at the given 0-based position. If the position is less than 0, or beyond the end of the string, the null character (0) is returned.
Example: compare a C string with a Str string character-by-character
LPCTSTR s_src = _T("SaMpLe 123");
Str s (s_src);
for (int i=0; i<s.GetLength(); i++) {
STRCHAR c1 = s_src[i];
STRCHAR c2 = s[i]; // Equivalent to s.GetAt(i)
ASSERT(c1 == c2);
}
See also: Basic operations