Access substring |
![]() |
|
|
|
|
|
|
|
|
|
|
These two methods will return a new string comprising of the first howmany characters in the source string (Left) or the last howmany (Right). If the parameter exceeds the total number of characters in the string, the whole string is returned.
|
|
|
|
|
This method will return a new string comprising of a portion of the source string, starting at 0-based character index start and going for howmany characters. If the beginning index exceeds the number of characters in the source, an empty string is returned. If the source contains less than howmany characters at the starting index, all characters till the end of the string are returned.
The second form of the method (with a single parameter) will return everything from start till the end of the string. Again, if the index is beyond the length of the string, an empty string is returned.
Example: break up and recombine string
Str s (_T("123 middle xyz"));
Str result = s.Left(3) + _T(" ") + s.Mid(4, 6) + _T(" ") + s.Right(3);
ASSERT (s == result);
See also: Basic operations