Freigeben über


CStringT::Mid

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;

Parameters

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

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

Return Value

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

Remarks

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.

Example

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

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

Requirements

Header: cstringt.h

See Also

Reference

CStringT Class

Other Resources

CStringT Members