Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All


Extracts a substring of length nCount characters from this CStringT object, starting at position iFirst (zero-based).

CStringT Mid(
   int iFirst,
   int nCount
) const;
CStringT Mid(
   int iFirst
) const;


The zero-based index of the first character in this CStringT object that is to be included in the extracted substring.


The number of characters to extract from this CStringT object. If this parameter is not supplied, then the remainder of the string is extracted.

A CStringT object that contains a copy of the specified range of characters. Note that the returned CStringT object may be empty.

The function returns a copy of the extracted substring. Mid is similar to the Basic Mid function (except that indexes in Basic are one-based).

For multibyte character sets (MBCS), nCount refers to each 8-bit character; that is, a lead and trail byte in one multibyte character are counted as two characters.

// typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;

CAtlString s(_T("abcdef"));
ASSERT(s.Mid(2, 3) == _T("cde"));   

Header: cstringt.h

Community Additions

© 2015 Microsoft