文档详情

CString成员函数详解.doc

发布:2016-10-31约6.69千字共7页下载文档
文本预览下载声明
CString类所有成员函数详解VC里CString是我们最常用的类之一,我们觉得对它很熟悉了,可是你知道它的所有用法吗?还是系统的学习一下吧,认真看完本文就OK了。下面开始:CString::Compare int Compare( LPCTSTR lpsz ) const; 返回值 字符串一样 返回0 ???????? 小于lpsz 返回-1 ???????? 大于lpsz 返回1 ???????? 区分大小字符 ???????? CString s1( abc ); CString s2( abd ); ASSERT( s1.Compare( s2 ) == -1 ); ASSERT( s1.Compare( abe ) == -1 );CString::CompareNoCase int CompareNoCase( LPCTSTR lpsz ) const; 返回值 字符串一样 返回0 ??????? 小于lpsz 返回-1 ??????? 大于lpsz 返回1 ??????? 不区分大小字符CString::Collate int Collate( LPCTSTR lpsz ) const; 同CString::CompareCString::CollateNoCase int CollateNocase( LPCTSTR lpsz ) const; 同CString::CompareNoCaseCString::CString CString( ); CString( const CString stringSrc ); CString( TCHAR ch, int nRepeat = 1 ); CString( LPCTSTR lpch, int nLength ); CString( const unsigned char* psz ); CString( LPCWSTR lpsz ); CString( LPCSTR lpsz ); 例子最容易说明问题 CString s1;????????????????????? CString s2( cat );?????????????? CString s3 = s2;????????????????? CString s4( s2 + + s3 );???????? CString s5( x );????????????????????? // s5 = x CString s6( x, 6 );?????????????????? // s6 = xxxxxx CString s7((LPCSTR)ID_FILE_NEW);??????? // s7 = Create a new document CString city = Philadelphia; CString::Delete int Delete( int nIndex, int nCount = 1); 返回值是被删除前的字符串的长度 nIndex是第一个被删除的字符,nCount是一次删除几个字符。根据我实验得出的结果:当nCount要删除字符串的最大长度(GetCount() - nIndex)时会出错,当nCount过大,没有足够的字符删除时,此函数不执行。 例子 CString str1,str2,str3; char a; str1 = nihao; str2 = nIhao; int x; // int i=(str1 == str2);?????? str1.Delete(2,3); 如果nCount(3) GetCount() – nIndex (5-2)就会执行错误CString::Empty Void Empty( ); 没有返回值 清空操作; 例子 CString s( abc ); s.Empty(); ASSERT( s.GetLength( ) == 0 );CString::Find int Find( TCHAR ch ) const; int Find( LPCTSTR lpszSub ) const; int Find( TCHAR ch, int nStart ) const; int Find( LPCTSTR lpszSub, int nStart ) const; 返回值 不匹配的话返回 -1; 索引以0 开始 ??????? nStar 代表以索引值nStart 的字符开始搜索 , 即为包含以索引nStart字符后的字符串 例子 CString s( abcdef ); ASSERT( s.Find( c ) == 2 ); ASSERT( s.Find( de ) == 3 ); Cstring str(“The
显示全部
相似文档