乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      CString常用方法一_無處&&心靈

       skywood 2007-04-25
      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是第一個(gè)被刪除的字符,nCount是一次刪除幾個(gè)字符。根據(jù)我實(shí)驗(yàn)得出的結(jié)果:當(dāng)nCount>要?jiǎng)h除字符串的最大長度(GetCount() - nIndex)時(shí)會(huì)出錯(cuò),當(dāng)nCount過大,沒有足夠的字符刪除時(shí),此函數(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)就會(huì)執(zhí)行錯(cuò)誤
      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 開始
                 注意::返回此字符串中第一個(gè)在lpszCharSet中也包括字符并且從零開始的索引值
      例子
      CString s( "abcdef" );
      ASSERT( s.FindOneOf( "xd" ) == 3 ); // ‘d‘ is first match.
      CString::Format
      void Format( LPCTSTR lpszFormat, ... );
      void Format( UINT nFormatID, ... );
      lpszFormat   一個(gè)格式控制字符串
      nFormatID   字符串標(biāo)識(shí)符
      例子
                    CString str;
      Str.Format(“%d”,13);
      此時(shí)Str為13
      CString::GetAt
      TCHAR GetAt( int nIndex ) const;
      返回標(biāo)號(hào)為nIndex的字符,你可以把字符串理解為一個(gè)數(shù)組,GetAt類似于[].注意nIndex的范圍,如果不合適會(huì)有調(diào)試錯(cuò)誤。
      CString::GetBuffer
      LPTSTR GetBuffer( int nMinBufLength );
      返回值
      一個(gè)指向?qū)ο蟮模ㄒ钥兆址Y(jié)尾的)字符緩沖區(qū)的LPTSTR 指針。
      參數(shù)
      nMinBufLength
      字符緩沖區(qū)的以字符數(shù)表示的最小容量。這個(gè)值不包括一個(gè)結(jié)尾的空字符的空間。
      說明
      此成員函數(shù)返回一個(gè)指向CString 對(duì)象的內(nèi)部字符緩沖區(qū)的指針。返回的LPTSTR 不是const,因此可以允許直接修改CString 的內(nèi)容。如果你使用由GetBuffer 返回的指針來改變字符串的內(nèi)容,你必須在使用其它的CString 成員函數(shù)之前調(diào)用ReleaseBuffer 函數(shù)。
      在調(diào)用ReleaseBuffer 之后,由GetBuffer 返回的地址也許就無效了,因?yàn)槠渌腃String 操作可能會(huì)導(dǎo)致CString 緩沖區(qū)被重新分配。如果你沒有改變此CString 的長度,則緩沖區(qū)不會(huì)被重新分配。當(dāng)此CString 對(duì)象被銷毀時(shí),其緩沖區(qū)內(nèi)存將被自動(dòng)釋放。
      注意,如果你自己知道字符串的長度,則你不應(yīng)該添加結(jié)尾的空字符。但是,當(dāng)你用ReleaseBuffer 來釋放該緩沖區(qū)時(shí),你必須指定最后的字符串長度。如果你添加了結(jié)尾的空字符,你應(yīng)該給ReleaseBuffer 的長度參數(shù)傳遞-1 ,ReleaseBuffer 將對(duì)該緩沖區(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 對(duì)象。
      s.ReleaseBuffer( );
      #ifdef _DEBUG
      afxDump << "CString s " << s << "\n";
      #endif
      CString::GetLength
      int GetLength( ) const;
      返回值
      返回字符串中的字節(jié)計(jì)數(shù)。
      說明
      此成員函數(shù)用來獲取這個(gè)CString 對(duì)象中的字節(jié)計(jì)數(shù)。這個(gè)計(jì)數(shù)不包括結(jié)尾的空字符。
      對(duì)于多字節(jié)字符集(MBCS),GetLength 按每一個(gè)8 位字符計(jì)數(shù);即,在一個(gè)多字節(jié)字符中的開始和結(jié)尾字節(jié)被算作兩個(gè)字節(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是字符(或字符串)插入后的索引號(hào)例子
      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!

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多