国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
CString常用方法一_無處&&心靈
CString::Compare
int Compare( LPCTSTR lpsz ) const;
返回值    字符串一樣返回0
          小于lpsz   返回-1
          大于lpsz   返回1
          區(qū)分大小字符
          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
         不區(qū)分大小字符
CString::Collate
int Collate( LPCTSTR lpsz ) const;
同CString::Compare
CString::CollateNoCase
int CollateNocase( LPCTSTR lpsz ) const;
同CString::CompareNoCase
CString::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是一次刪除幾個字符。根據(jù)我實驗得出的結(jié)果:當nCount>要刪除字符串的最大長度(GetCount() - nIndex)時會出錯,當nCount過大,沒有足夠的字符刪除時,此函數(shù)不執(zhí)行。
例子
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)就會執(zhí)行錯誤
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 stars are aligned”);
Ing n = str.Find(‘e‘,5);
ASSERT(n == 12)
CString::FindOneOf
int FindOneOf( LPCTSTR lpszCharSet ) const;
返回值   不匹配的話返回 -1;   索引以0 開始
           注意::返回此字符串中第一個在lpszCharSet中也包括字符并且從零開始的索引值
例子
CString s( "abcdef" );
ASSERT( s.FindOneOf( "xd" ) == 3 ); // ‘d‘ is first match.
CString::Format
void Format( LPCTSTR lpszFormat, ... );
void Format( UINT nFormatID, ... );
lpszFormat   一個格式控制字符串
nFormatID   字符串標識符
例子
              CString str;
Str.Format(“%d”,13);
此時Str為13
CString::GetAt
TCHAR GetAt( int nIndex ) const;
返回標號為nIndex的字符,你可以把字符串理解為一個數(shù)組,GetAt類似于[].注意nIndex的范圍,如果不合適會有調(diào)試錯誤。
CString::GetBuffer
LPTSTR GetBuffer( int nMinBufLength );
返回值
一個指向?qū)ο蟮模ㄒ钥兆址Y(jié)尾的)字符緩沖區(qū)的LPTSTR 指針。
參數(shù)
nMinBufLength
字符緩沖區(qū)的以字符數(shù)表示的最小容量。這個值不包括一個結(jié)尾的空字符的空間。
說明
此成員函數(shù)返回一個指向CString 對象的內(nèi)部字符緩沖區(qū)的指針。返回的LPTSTR 不是const,因此可以允許直接修改CString 的內(nèi)容。如果你使用由GetBuffer 返回的指針來改變字符串的內(nèi)容,你必須在使用其它的CString 成員函數(shù)之前調(diào)用ReleaseBuffer 函數(shù)。
在調(diào)用ReleaseBuffer 之后,由GetBuffer 返回的地址也許就無效了,因為其它的CString 操作可能會導致CString 緩沖區(qū)被重新分配。如果你沒有改變此CString 的長度,則緩沖區(qū)不會被重新分配。當此CString 對象被銷毀時,其緩沖區(qū)內(nèi)存將被自動釋放。
注意,如果你自己知道字符串的長度,則你不應該添加結(jié)尾的空字符。但是,當你用ReleaseBuffer 來釋放該緩沖區(qū)時,你必須指定最后的字符串長度。如果你添加了結(jié)尾的空字符,你應該給ReleaseBuffer 的長度參數(shù)傳遞-1 ,ReleaseBuffer 將對該緩沖區(qū)執(zhí)行strlen 來確定它的長度。
下面的例子說明了如何用CString::GetBuffer。
// CString::GetBuffer 例子
CString s( "abcd" );
#ifdef _DEBUG
afxDump << "CString s " << s << "\n";
#endif
LPTSTR p = s.GetBuffer( 10 );
strcpy( p, "Hello" ); // 直接訪問CString 對象。
s.ReleaseBuffer( );
#ifdef _DEBUG
afxDump << "CString s " << s << "\n";
#endif
CString::GetLength
int GetLength( ) const;
返回值
返回字符串中的字節(jié)計數(shù)。
說明
此成員函數(shù)用來獲取這個CString 對象中的字節(jié)計數(shù)。這個計數(shù)不包括結(jié)尾的空字符。
對于多字節(jié)字符集(MBCS),GetLength 按每一個8 位字符計數(shù);即,在一個多字節(jié)字符中的開始和結(jié)尾字節(jié)被算作兩個字節(jié)。
示例
下面的例子說明了如何使用CString::GetLength。
// CString::GetLength 示例
CString s( "abcdef" );
ASSERT( s.GetLength() == 6 );
CString::Insert
int Insert( int nIndex, TCHAR ch );
int Insert( int nIndex, LPCTSTR pstr );
返回修改后的長度,nIndex是字符(或字符串)插入后的索引號例子
CString str( “HockeyBest”);
int n = str.Insert( 6, “is” );
ASSERT( n == str.GetLength( ) );
printf( “1: %s\n”, ( LPCTSTR ) str );
n = str.Insert( 6, ‘ ‘ );
ASSERT( n == str.GetLength( ) );
printf ( “2: %s\n”, (LPCTSTR) STR );
n = str.Insert(555, ‘1’);
ASSERT( n == str.GetLength ( ) );
printf ( “3: %s\n”, ( LPCTSTR ) str );
輸出
1. Hockeyis Best
2. Hockey is Best
3. Hockey is Best!
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
VC:CString用法整理(轉(zhuǎn)載)
WinCE下常用但缺少的功能函數(shù)(UuidCreate、ini文件操作)
CString 成員函數(shù)用法大全 - C++ 代碼 - 博客園
將CString類轉(zhuǎn)換成char*類型
使用"查找/替換"對話框在文本中替換字符串
VC++-數(shù)據(jù)加密
更多類似文章 >>
生活服務
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服