c++ MFC中怎样获取部分字符串?

c++ MFC中怎样获取部分字符串,定义CSring s=“adbdksf”比如获取第二个到第四个字符


梵蒂冈之花
浏览 1620回答 3
3回答

慕容3067478

CString 有下面几个函数Mid Extracts the middle part of a string (like the Basic MID$ function).Left Extracts the left part of a string (like the Basic LEFT$ function).Right Extracts the right part of a string (like the Basic RIGHT$ function).SpanIncluding Extracts a substring that contains only the characters in a set.SpanExcluding Extracts a substring that contains only the characters not in a set.点 MidCString::MidCString Mid( int nFirst ) const;throw( CMemoryException );CString Mid( int nFirst, int nCount ) const;throw( CMemoryException );Return ValueA CString object that contains a copy of the specified range of characters. Note that the returned CString object may be empty.ParametersnFirstThe zero-based index of the first character in this CString object that is to be included in the extracted substring.nCountThe number of characters to extract from this CString object. If this parameter is not supplied, then the remainder of the string is extracted.RemarksExtracts a substring of length nCount characters from this CString object, starting at position nFirst (zero-based). The function returns a copy of the extracted substring. Mid is similar to the Basic MID$ function (except that indexes are zero-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.ExampleThe following example demonstrates the use of CString::Mid.// example for CString::MidCString s( _T("abcdef") );ASSERT( s.Mid( 2, 3 ) == _T("cde") );第2到第4(序号是从0开始的 indexes are zero-based,第2个就是1,2到4总共3个字符)s,Mid(1,3)

慕虎7371278

用CString的Mid函数,第一个参数是从第几个开始,第二个参数是取多少个,返回值是一个新的CString对象。如CString str = "123456";CString substr = str.Mid(2,2);返回“34“

翻过高山走不出你

cstring c;c.assign(s,2,4);头文件#include<string.h>建议看下c++模板
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Oracle