zoukankan      html  css  js  c++  java
  • CString

    ______CString::Left.

    Return Value:   CString object containing a copy of the specified range of characters. Note that the returnedCString object may be empty.

    // example for CString::Left
    CString s( _T("abcdef") );
    ASSERT( s.Left(2) == _T("ab") );

    //int GetLength( ) const;The count does not include a null terminator.
    int c = s.GetLength();
    //LPTSTR GetBuffer( int nMinBufLength );
    nMinBufLength does not include a null terminator.
    LPTSTR p = s.GetBuffer(c);

    Returns a pointer to the internal character buffer for the CString object. The returned LPTSTR is not const and thus allows direct modification of CString contents.

    If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before using any other CString member functions.

    The address returned by GetBuffer may not be valid after the call to ReleaseBuffer since additional CStringoperations may cause the CString buffer to be reallocated. The buffer will not be reallocated if you do not change the length of the CString.

    The buffer memory will be freed automatically when the CString object is destroyed.

    Note that if you keep track of the string length yourself, you should not append the terminating null character. You must, however, specify the final string length when you release the buffer with ReleaseBuffer. If you do append a terminating null character, you should pass –1 for the length to ReleaseBuffer and ReleaseBuffer will perform astrlen on the buffer to determine its length.

    Example

    The following example demonstrates the use of CString::GetBuffer.

    // example for CString::GetBuffer
    CString s( "abcd" );
    #ifdef _DEBUG
    afxDump << "CString s " << s << "
    ";
    #endif
    LPTSTR p = s.GetBuffer( 10 );
    strcpy( p, "Hello" );   // directly access CString buffer
    s.ReleaseBuffer( );
    #ifdef _DEBUG
    afxDump << "CString s " << s << "
    ";
    #endif
     
  • 相关阅读:
    String.trim()这个细节不能忘记
    Integer.parseInt(f.trim())中String f要加trim()
    类属性不能写在try{}catch(){}里面
    011--TypeScript泛型
    010--TypeScript里面的this和重载
    009--函数(基本实例和函数类型)
    007--TypeScript之类的修饰符
    008--TypeScript存储器和静态属性
    006--TypeScript之类
    005--TypeScript接口
  • 原文地址:https://www.cnblogs.com/aprilapril/p/3224086.html
Copyright © 2011-2022 走看看