请输入您要查询的百科知识:

 

词条 CString::Mid
释义

CString::Mid

说明:

此成员函数从此CString对象中提取一个长度为nCount个字符的子串,从nFirst(从零开始的索引)指定的位置开始。此函数返回一个对所提取的字符串的拷贝。Mid类似于Basic MID$函数(除了索引是从零开始的)。

CString Mid( int nFirst ) const;

throw( CMemoryException );

CString Mid( int nFirst, int nCount ) const;

throw( CMemoryException );

返回值:

返回一个包含指定范围字符的拷贝的CString对象。注意,这个返回的CString对象可能是空的。

参数:

nFirst 此CString对象中的要被提取的子串的第一个字符的从零开始的索引。

nCount 要从此CString对象中提取的字符数。如果没有提供这个参数,则字符串的其余部分都被提取。

对于多字节字符集(MBCS),nCount指的是每8位字符的数目;也就是说,在一个多字节字符中开始和结尾字节被算作两个字符。

示例:下面的例子说明了如果如何使用CString::Mid。

// CString::Mid示例:

CString s( _T("abcdef") );

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

以下为MSDN说明:

CString::Mid

This method extracts a substring of length nCount characters from this CString object, starting at position nFirst (zero-based). The method returns a copy of the extracted substring. Mid is similar to the Basic MID$ function, except that indexes are zero-based.

CString Mid(

int nFirst,

int nCount )

const;

CString Mid(

int nFirst )

const;

Parameters

nFirst

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

nCount

Specifies the number of characters to extract from this CString object. If this parameter is not supplied, the remainder of the string is extracted.

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

Example The following example demonstrates the use of CString::Mid.

// example for CString::Mid

CString s( _T("abcdef") );

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

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/2/12 20:54:26