• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 131, comments - 12, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            CString 成員函數(shù)用法大全

            Posted on 2012-09-21 09:01 盛勝 閱讀(342) 評論(0)  編輯 收藏 引用 所屬分類: ftp客戶端
            CString的構(gòu)造函數(shù)
            CString( );
            例:CString csStr;

            CString( const CString& stringSrc );
            例:CString csStr("ABCDEF中文123456");
                CString csStr2(csStr);

            CString( TCHAR ch, int nRepeat = 1 );
            例:CString csStr('a',5);
            //csStr="aaaaa"

            CString( LPCTSTR lpch, int nLength );
            例:CString csStr("abcdef",3);
            //csStr="abc"

            CString( LPCWSTR lpsz );
            例:wchar_t s[]=L"abcdef";
                CString csStr(s);
            //csStr=L"abcdef"

            CString( const unsigned char* psz );
            例:const unsigned char s[]="abcdef";
                const unsigned char* sp=s;
                CString csStr(sp);
            //csStr="abcdef"

            CString( LPCSTR lpsz );
            例:CString csStr("abcdef");
            //csStr="abcdef"

            int GetLength( ) const;
            返回字符串的長度,不包含結(jié)尾的空字符。
            例:csStr="ABCDEF中文123456";
                printf("%d",csStr.GetLength());       //16

            void MakeReverse( );
            顛倒字符串的順序
            例:csStr="ABCDEF中文123456";
                csStr.MakeReverse();
                cout<<csStr;                  //654321文中FEDCBA

            void MakeUpper( );
            將小寫字母轉(zhuǎn)換為大寫字母
            例:csStr="abcdef中文123456";
                csStr.MakeUpper();
                cout<<csStr;                  //ABCDEF中文123456

            void MakeLower( );
            將大寫字母轉(zhuǎn)換為小寫字母
            例:csStr="ABCDEF中文123456";
                csStr.MakeLower();
                cout<<csStr;                  //abcdef中文123456

            int Compare( LPCTSTR lpsz ) const;
            區(qū)分大小寫比較兩個字符串,相等時返回0,大于時返回1,小于時返回-1
            例:csStr="abcdef中文123456";
                csStr2="ABCDEF中文123456";
                cout<<csStr.CompareNoCase(csStr2);             //0

            int CompareNoCase( LPCTSTR lpsz ) const;
            不區(qū)分大小寫比較兩個字符串,相等時返回0,大于時返回1,小于時返回-1
            例:csStr="abcdef中文123456";
                csStr2="ABCDEF中文123456";
                cout<<csStr.CompareNoCase(csStr2);             //-1

            int Delete( int nIndex, int nCount = 1 )
            刪除字符,刪除從下標nIndex開始的nCount個字符
            例:csStr="ABCDEF";
                csStr.Delete(2,3);
                cout<<csStr;              // ABF
            //當nIndex過大,超出對像所在內(nèi)存區(qū)域時,函數(shù)沒有任何操作。
            //當nIndex為負數(shù)時,從第一個字符開始刪除。
            //當nCount過大,導(dǎo)致刪除字符超出對像所在內(nèi)存區(qū)域時,會發(fā)生無法預(yù)料的結(jié)果。
            //當nCount為負數(shù)時,函數(shù)沒有任何操作。

            int Insert( int nIndex, TCHAR ch )
            int Insert( int nIndex, LPCTSTR pstr )

            在下標為nIndex的位置,插入字符或字符串。返回插入后對象的長度
            例:csStr="abc";
                csStr.Insert(2,'x');
                cout<<csStr;                     //abxc
                csStr="abc";
                csStr.Insert(2,"xyz");
                cout<<csStr;                     //abxyzc
            //當nIndex為負數(shù)時,插入在對象開頭
            //當nIndex超出對象末尾時,插入在對象末尾

            int Remove( TCHAR ch );
            移除對象內(nèi)的指定字符。返回移除的數(shù)目
            例:csStr="aabbaacc";
                csStr.Remove('a');
                cout<<csStr;                     //bbcc

            int Replace( TCHAR chOld, TCHAR chNew );
            int Replace( LPCTSTR lpszOld, LPCTSTR lpszNew );

            替換字串
            例:csStr="abcdef";
                csStr.Replace('a','x');
                cout<<csStr;                    //xbcdef
                csStr="abcdef";
                csStr.Replace("abc","xyz");
                cout<<csStr;                    //xyzdef

            void TrimLeft( );
            void TrimLeft( TCHAR chTarget );
            void TrimLeft( LPCTSTR lpszTargets );

            從左刪除字符,被刪的字符與chTarget或lpszTargets匹配,一直刪到第一個不匹配的字符為止
            例:csStr="aaabaacdef";
                csStr.TrimLeft('a');
                cout<<csStr;                //baacdef
                csStr="aaabaacdef";
                csStr.TrimLeft("ab");
                cout<<csStr;                //cdef
            //無參數(shù)時刪除空格

            void TrimRight( );
            void TrimRight( TCHAR chTarget );
            void TrimRight( LPCTSTR lpszTargets );

            從右刪除字符,被刪的字符與chTarget或lpszTargets匹配,一直刪到第一個不匹配的字符為止
            例:csStr="abcdeaafaaa";
                csStr.TrimRight('a');
                cout<<csStr;               //abcdeaaf
                csStr="abcdeaafaaa";
                csStr.TrimRight("fa");
                cout<<csStr;                //abcde
            //無參數(shù)時刪除空格

            void Empty( );
            清空
            例:csStr="abcdef";
                csStr.Empty();
                printf("%d",csStr.GetLength());    //0

            BOOL IsEmpty( ) const;
            測試對象是否為空,為空時返回零,不為空時返回非零
            例:csStr="abc";
                cout<<csStr.IsEmpty();         //0;
                csStr.Empty();
                cout<<csStr.IsEmpty();         //1;

            int Find( TCHAR ch ) const;
            int Find( LPCTSTR lpszSub ) const;
            int Find( TCHAR ch, int nStart ) const;
            int Find( LPCTSTR pstr, int nStart ) const;

            查找字串,nStart為開始查找的位置。未找到匹配時返回-1,否則返回字串的開始位置
            例:csStr="abcdef";
                cout<<csStr.Find('b');       //1
                cout<<csStr.Find("de");      //3
                cout<<csStr.Find('b',3);     //-1
                cout<<csStr.Find('b',0);     //1
                cout<<csStr.Find("de",4);    //-1
                cout<<csStr.Find("de",0);    //3
            //當nStart超出對象末尾時,返回-1。
            //當nStart為負數(shù)時,返回-1。

            int FindOneOf( LPCTSTR lpszCharSet ) const;
            查找lpszCharSet中任意一個字符在CString對象中的匹配位置。未找到時返回-1,否則返回字串的開始位置
            例:csStr="abcdef";
                cout<<csStr.FindOneOf("cxy");       //2

            CString SpanExcluding( LPCTSTR lpszCharSet ) const;
            返回對象中與lpszCharSet中任意匹配的第一個字符之前的子串
            例:csStr="abcdef";
                cout<<csStr.SpanExcluding("cf");    //ab

            CString SpanIncluding( LPCTSTR lpszCharSet ) const;
            從對象中查找與lpszCharSe中任意字符不匹配的字符,并返回第一個不匹配字符之前的字串
            例:csStr="abcdef";
                cout<<csStr.SpanIncluding("fdcba");    //abcd

            int ReverseFind( TCHAR ch ) const;
            從后向前查找第一個匹配,找到時返回下標。沒找到時返回-1
            例:csStr="abba";
                cout<<csStr.ReverseFind('a');        //3

            void Format( LPCTSTR lpszFormat, ... );
            void Format( UINT nFormatID, ... );

            格式化對象,與C語言的sprintf函數(shù)用法相同
            例:csStr.Format("%d",13);
                cout<<csStr;                       //13

            TCHAR GetAt( int nIndex ) const;
            返回下標為nIndex的字符,與字符串的[]用法相同
            例:csStr="abcdef";
                cout<<csStr.GetAt(2);             //c
            //當nIndex為負數(shù)或超出對象末尾時,會發(fā)生無法預(yù)料的結(jié)果。

            void SetAt( int nIndex, TCHAR ch );
            給下標為nIndex的字符重新賦值
            例:csStr="abcdef";
                csStr.SetAt(2,'x');
                cout<<csStr;                      //abxdef
            //當nIndex為負數(shù)或超出對象末尾時,會發(fā)生無法預(yù)料的結(jié)果。

            CString Left( int nCount ) const;
            從左取字串
            例:csStr="abcdef";
                cout<<csStr.Left(3);           //abc
            //當nCount等于0時,返回空。
            //當nCount為負數(shù)時,返回空。
            //當nCount大于對象長度時,返回值與對象相同。

            CString Right( int nCount ) const;
            從右取字串
            例:csStr="abcdef";
                cout<<csStr.Right(3);           //def
            //當nCount等于0時,返回空。
            //當nCount為負數(shù)時,返回空。
            //當nCount大于對象長度時,返回值與對象相同。

            CString Mid( int nFirst ) const;
            CString Mid( int nFirst, int nCount ) const;

            從中間開始取字串
            例:csStr="abcdef";
                cout<<csStr.Mid(2);           //cdef
                csStr="abcdef";
                cout<<csStr.Mid(2,3);         //cde
            //當nFirst為0和為負數(shù)時,從第一個字符開始取。
            //當nFirst等于對象末尾時,返回空字串。
            //當nFirst超出對象末尾時,會發(fā)生無法預(yù)料的結(jié)果。
            //當nCount超出對象末尾時,返回從nFirst開始一直到對象末尾的字串
            //當nCount為0和為負數(shù)時,返回空字串。

            LPTSTR GetBuffer( int nMinBufLength );
            申請新的空間,并返回指針
            例:csStr="abcde";
                LPTSTR pStr=csStr.GetBuffer(10);
                strcpy(pStr,"12345");
                csStr.ReleaseBuffer();
                pStr=NULL;
                cout<<csStr                 //12345
            //使用完GetBuffer后,必須使用ReleaseBuffer以更新對象內(nèi)部數(shù)據(jù),否則會發(fā)生無法預(yù)料的結(jié)果。

            void ReleaseBuffer( int nNewLength = -1 );
            使用GetBuffer后,必須使用ReleaseBuffer以更新對象內(nèi)部數(shù)據(jù)
            例:csStr="abc";
                LPTSTR pStr=csStr.GetBuffer(10);
                strcpy(pStr,"12345");
                cout<<csStr.GetLength();       //3(錯誤的用法)
                csStr.ReleaseBuffer();
                cout<<csStr.GetLength();       //5(正確)
                pStr=NULL;
            //CString對象的任何方法都應(yīng)在ReleaseBuffer之后調(diào)用

            LPTSTR GetBufferSetLength( int nNewLength );
            申請新的空間,并返回指針
            例:csStr="abc";
                csStr.GetBufferSetLength(20);
                cout<<csStr;                  //abc
                count<<csStr.GetLength();     //20;
                csStr.ReleaseBuffer();
                count<<csStr.GetLength();     //3;
            //使用GetBufferSetLength后可以不必使用ReleaseBuffer。



            CString ImagePath = "d:/abc/dd.avi";
            int i = ImagePath.ReverseFind(_T('/'));
            CString strtest = ImagePath.Left(i+1);


            pasting
            久久这里只有精品久久| 亚洲精品无码久久久久| 久久综合久久综合九色| 97久久精品人人澡人人爽 | 久久综合九色欧美综合狠狠| 久久97久久97精品免视看| 久久中文字幕人妻丝袜| AAA级久久久精品无码片| 久久精品18| 久久久久人妻精品一区二区三区| 久久被窝电影亚洲爽爽爽| 一级a性色生活片久久无| 狠狠色噜噜狠狠狠狠狠色综合久久 | 一本一道久久a久久精品综合| 久久丫精品国产亚洲av不卡| 色婷婷久久综合中文久久一本| 久久发布国产伦子伦精品| 久久中文字幕精品| 久久人搡人人玩人妻精品首页| 久久婷婷五月综合97色一本一本| 久久久无码精品亚洲日韩软件| MM131亚洲国产美女久久| 久久久久av无码免费网| 久久综合精品国产一区二区三区| 国产精品一久久香蕉产线看| 久久夜色精品国产噜噜亚洲a| 国内精品久久久久伊人av| 亚洲国产精品无码久久久不卡 | 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 久久亚洲国产精品一区二区| 久久丫忘忧草产品| 精品久久久久成人码免费动漫| 久久精品国产一区二区电影| 国产精品一久久香蕉国产线看| 久久av无码专区亚洲av桃花岛| 久久精品国产色蜜蜜麻豆| 热久久最新网站获取| 久久天天婷婷五月俺也去| 久久免费看黄a级毛片| 久久久久se色偷偷亚洲精品av| 国内精品久久国产|