C++?CString?÷????
???????????? ???????[ 2014/12/18 11:22:59 ] ????????C++ ???????
???????GetBuffer?????????ReleaseBuffer???????????????
????????csStr="abc";
????LPTSTR pStr=csStr.GetBuffer(10);
????strcpy(pStr??"12345");
????cout<<csStr.GetLength(); //3(??????÷?)
????csStr.ReleaseBuffer();
????cout<<csStr.GetLength(); //5(???)
????pStr=NULL;
????//CString??????κη????????ReleaseBuffer??????
????LPTSTR GetBufferSetLength( int nNewLength );
?????????μ????????????
????????csStr="abc";
????csStr.GetBufferSetLength(20);
????cout<<csStr; //abc
????count<<csStr.GetLength(); //20;
????csStr.ReleaseBuffer();
????count<<csStr.GetLength(); //3;
????//???GetBufferSetLength???????????ReleaseBuffer??
????1.CString::IsEmpty
????BOOL IsEmpty( ) const;
??????????????CString ?????????0??????????????????0??
????????????????????????????CString ????????????
?????????
????????????????????????CString::IsEmpty??
????// CString::IsEmpty ???
????CString s;
????ASSERT( s.IsEmpty() );
????????? CString::GetLength
????2.CString::Left
????CString Left( int nCount ) const;
????throw( CMemoryException );
????????????????????????nCount???????
?????????
????CString s( _T("abcdef") );
????ASSERT( s.Left(2) == _T("ab") );
????3.CString::LoadString
????BOOL LoadString( UINT nID );
????throw( CMemoryException );
????????????????????????????????????????0??
????nID ???Windows ????????ID??
????????? ????????????????????nID ?????Windows ???????????????????????CString ?????С?
?????????
????????????????????????CString::LoadString??
????// CString::LoadString ???
????#define IDS_FILENOTFOUND 1
????CString s;
????if (! s.LoadString( IDS_FILENOTFOUND ))
????4.CString::MakeLower
????void MakeLower( ); //????????Сд
????5.CString::MakeReverse
????void MakeReverse( ); //???????
????6.CString::MakeUpper
????void MakeUpper( ); //?????????д
????7.CString::Mid
????CString Mid( int nFirst ) const;
????CString Mid( int nFirst?? int nCount ) const;
????nCount????????????????? nFirst????????????????λ??
?????????
????CString s( _T("abcdef") );
????ASSERT( s.Mid( 2?? 3 ) == _T("cde") );
????8.CString::ReleaseBuffer
????void ReleaseBuffer( int nNewLength = -1 );
????????:nNewLength
??????????????????????????3???????????β????????????????
??????????????????β???????????????1 ????CString ???С?????
??????????????????
?????????
???????ReleaseBuffer ??????????GetBuffer ??????????????á???????????
?????????е????????????????β???????????nNewLength ????????????
??????????????????β???????????nNewLength ???????????????????
????ReleaseBuffer ??????CString ?????????GetBuffer ???????????Ч???
?????????
????????????????????????CString::ReleaseBuffer??
????// CString::ReleaseBuffer ???
????CString s;
????s = "abc";
????LPTSTR p = s.GetBuffer( 1024 );
????strcpy(p?? "abc"); // ????????????
????ASSERT( s.GetLength() == 3 ); // ????????? = 3
????s.ReleaseBuffer(); // ?????????棬????p ??Ч??
????ASSERT( s.GetLength() == 3 ); // ?????????3
????9.CString::Remove
????int CString::Remove ( TCHAR ch );
?????????:??????????????????????????????????и????????
????????:ch ???????????????????????
???????:??????????????ch ????????????????????????????????????Сд
???????
???????:
????// ???????????????Сд???'c':
????CString str (“This is a test.”);
????int n = str.Remove( 't' );
????ASSERT( n == 2 );
????ASSERT( str ==“This is a es. ” );
????10.CString::Replace
????int Replace( TCHAR chOld?? TCHAR chNew );
????int Replace( LPCTSTR lpszOld?? LPCTSTR lpszNew );
?????????:??????滻??????????????????????и????????
????????:chOld ???chNew ?滻???????
????chNew ??????滻chOld ???????
????lpszOld ????????????????????????????????lpszNew ?滻???????
????LpszNew ???????????????????????????????????滻lpszOld ???????
???????:?????????????????滻??????????????????????????????????chNew
????????滻chOld?????????????????lpszNew ???????????滻lpszOld ???
???????????
???????滻???????????п?????????????????????lpszNew ??lpszOld ?????
????????????????????汾??????????????Сд?????
???????:
????// ??????????old ??new ?????????????
????CString strZap( “C - -” );
????int n = strZap.Replace('-'?? '+' );
????ASSERT( n == 2 );
????ASSERT(strZap == “C++” );
????// ??????????old ??new ???в????????
????CString strBang( “Everybody likes ice hockey” );
????n = strBang.Replace( “hockey”?? “golf” );
????ASSERT( n ==1 );
????n = strBang.Replace ( “likes” ?? “plays” );
????ASSERT( n == 1 );
????n = strBang.Replace( “ice”?? NULL );
????ASSERT( n == 1 );
????ASSERT( strBang == “Everybody plays golg” );
????// ???????????????????????????????
????// ????????????????????????????????滻????????У????磬“ice ”??
????11.CString::ReverseFind
????int ReverseFind( TCHAR ch ) const;
?????????: ?????CString ??????????????????????????????????????????
??????????????????-1??
????????: ch ????????????
???????:???????????CString ????????????????????????????????????
???????????????????strrchr??
???????:
????// CString::ReverseFind ???
????CString s( "abcabc" );
????ASSERT( s.ReverseFind( 'b' ) == 4 );
????12.CString::Right
????CString Right( int nCount ) const;
????throw( CMemoryException );
??????????? ?????????????nCount???????
????CString s( _T("abcdef") );
????ASSERT( s.Right(2) == _T("ef") );
????13.CString:: SetAt
????void SetAt( int nIndex?? TCHAR ch );
?????????????????????????????飬SetAt??????[].???nIndex???Χ?????????????е?????? Ch ????????? ??nIndexλ???????? ???ch
?????????
????CString s( "abc" );
????s.MakeReverse();
????ASSERT( s == "cba" );
????14.CString::TrimLeft
????void TrimLeft( );
????void CString::TrimLeft( TCHAR chTarget );
??????????????в???????????????(
????)?????????????????????. ??????????????????Щ???. ??????????????????????????????е??????????.
????
???з?
???? TAB???
???????1??
????CString str = "
a";
????str.TrimLeft();
????str?“a”;
???????2??
????CString str = "abbcadbabcadb ";
????str.TrimLeft("ab");
???????"cadbabcadb "
????str.TrimLeft("ac");
???????"bcadbabcadb "
????15.CString::TrimRight
????void TrimRight( );
????void CString::TrimRight( TCHAR chTarget );
????void CString::TrimRight( LPCTSTR lpszTargets );
??????????÷??????????檔
????16.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
????17.CString::CompareNoCase
????int CompareNoCase( LPCTSTR lpsz ) const;
??????????? ???????? ????0??С??lpsz ????-1??????lpsz ????1?????????С???
????18.CString::Collate
????int Collate( LPCTSTR lpsz ) const;
?????CString::Compare
????19.CString::CollateNoCase
????int CollateNocase( LPCTSTR lpsz ) const;
?????CString::CompareNoCase
????20.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";
????21.CString::Delete
????int Delete( int nIndex?? int nCount = 1);
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11