c 위주로 하다보니 csting관련 메소드를 잘 몰라서...ㅠ_ㅠ..
할때 마다 찾기 귀찮귀~~
퍼온곳: http://blog.search.co.kr/tb.blog/41/380
CString class
CString 은 CObject에서 상속을 받지않고 Simple Value Types의 하나이다.
CString object 는 문자들의 가변적인 길이의 연속으로 구성되고, 문자 배열보다 사용하기가 쉽다. CString은 TCHAR 데이터 타입을 기초로 하고 있다.
n CString Class Members
Ø Construction
CString - CString의 생성자 ( CString :: CString )
CString( );
CString( const CString& stringSrc ); throw( CMemoryException );
CString( TCHAR ch, int nRepeat = 1 ); throw( CMemoryException );
CString( LPCTSTR lpch, int nLength ); throw( CMemoryException );
CString( const unsigned char* psz ); throw( CMemoryException );
CString( LPCWSTR lpsz ); throw( CMemoryException );
CString( LPCSTR lpsz ); throw( CMemoryException );
Example
// example for CString::CString
CString s1; // Empty string
CString s2( "cat" ); // From a C string literal
CString s3 = s2; // Copy constructor
CString s4( s2 + " " + s3 ); // From a string expression
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"; // NOT the assignment operator
Ø The String as an Array
GetLength : 설정된 문자열의 길이를 리턴
int GetLength( ) const;
IsEmpty : 문자열의 버퍼가 비워져 있는지를 검사
BOOL IsEmpty( ) const;
Empty : 문자열을 삭제하여 버퍼를 비운다.
void Empty( );
GetAt : 특정위치의 문자값을 얻는다.
TCHAR GetAt( int nIndex ) const;
operator []
TCHAR operator []( int nIndex ) const
SetAt
void SetAt( int nIndex, TCHAR ch );
operator LPCTSTR
operator LPCTSTR ( ) const;
Ø Assignment / Concatenation
Operator =
const CString& operator =( const CString& stringSrc ); throw( CMemoryException );
const CString& operator =( TCHAR ch ); throw( CMemoryException );
const CString& operator =( const unsigned char* psz ); throw( CMemoryException );
const CString& operator =( LPCWSTR lpsz ); throw( CMemoryException );
const CString& operator =( LPCSTR lpsz ); throw( CMemoryException );
Operator +
friend CString operator +( const CString& string1, const CString& string2 );
throw( CMemoryException );
friend CString operator +( const CString& string, TCHAR ch );
throw( CMemoryException );
friend CString operator +( TCHAR ch, const CString& string );
throw( CMemoryException );
friend CString operator +( const CString& string, LPCTSTR lpsz );
throw( CMemoryException );
friend CString operator +( LPCTSTR lpsz, const CString& string );
throw( CMemoryException );
Operator +=
const CString& operator +=( const CString& string ); throw( CMemoryException );
const CString& operator +=( TCHAR ch ); throw( CMemoryException );
const CString& operator +=( LPCTSTR lpsz ); throw( CMemoryException );
Ø Comparison
Operator == <, etc
Compare : 대소문자 구분
int Compare( LPCTSTR lpsz ) const;
CompareNoCase : 대소문자 구분 안함
int CompareNoCase( LPCTSTR lpsz ) const;
Collate
int Collate( LPCTSTR lpsz ) const
CollateNoCase
int CollateNoCase( LPCTSTR lpsz ) const;
Ø Extraction
Mid : 문자열의 중간부분을 추출한다.
CString Mid( int nFirst ) const; throw( CMemoryException );
CString Mid( int nFirst, int nCount ) const; throw( CMemoryException );
Left : 문자열의 왼쪽부분은 추출한다.
CString Left( int nCount ) const; throw( CMemoryException );
Right : 문자열의 오른쪽부분을 추출한다.
CString Right( int nCount ) const; throw( CMemoryException );
SpanIncluding : 포함된 문자를 추출
CString SpanIncluding( LPCTSTR lpszCharSet ) const throw( CMemoryException );
SpanExcluding
CString SpanExcluding( LPCTSTR lpszCharSet ) const; throw( CMemoryException );
Ø Other Conversions
MakeUpper : 소문자를 대문자로 바꾼다.
void MakeUpper( );
MakeLower : 대문자를 소문자로 바꾼다.
void MakeLower( );
MakeReverse : 문자를 reverse 시킨다.
void MakeReverse( );
Replace
int Replace( TCHAR chOld, TCHAR chNew );
int Replace( LPCTSTR lpszOld, LPCTSTR lpszNew );
Remove : 문자를 제거한다.
int CString::Remove( TCHAR ch );
Insert
int Insert( int nIndex, TCHAR ch ) throw( CMemoryException );
int Insert( int nIndex, LPCTSTR pstr ) throw( CMemoryException );
Delete
int Delete( int nIndex, int nCount = 1 ) throw( CMemoryException );
Format : sprintf와 비슷하다.
void Format( LPCTSTR lpszFormat, ... );
void Format( UINT nFormatID, ... );
FormatV
void FormatV( LPCTSTR lpszFormat, va_list argList );
TrimLeft
void TrimLeft( );
void CString::TrimLeft( TCHAR chTarget );
void CString::TrimLeft( LPCTSTR lpszTargets );
TrimRight
void TrimRight( );
void CString::TrimRight( TCHAR chTarget );
void CString::TrimRight( LPCTSTR lpszTargets );
FormatMessage
void FormatMessage( LPCTSTR lpszFormat, ... );
void FormatMessage( UINT nFormatID, ... );
Ø Serching
Find : 문자의 인덱스를 찾아 반환한다.
int Find( TCHAR ch ) const;
int Find( LPCTSTR lpszSub ) const;
int Find( TCHAR ch, int nStart ) const;
int Find( LPCTSTR pstr, int nStart ) const;
ReverseFind : 뒤에서부터 찾는다.
int ReverseFind( TCHAR ch ) const;
FindOneOf
int FindOneOf( LPCTSTR lpszCharSet ) const;
Ø Archive / Dump
Operator <<, Operator >>
friend CArchive& operator <<( CArchive& ar, const CString& string );
throw( CArchiveException );
friend CArchive& operator >>( CArchive& ar, CString& string );
throw( CArchiveException );
friend CDumpContext& operator <<( CDumpContext& dc, const CString& string );
Ø Buffer Access
GetBuffer
LPTSTR GetBuffer( int nMinBufLength ); throw( CMemoryException );
GetBufferSetLength
LPTSTR GetBufferSetLength( int nNewLength ); throw( CMemoryException );
ReleaseBuffer
void ReleaseBuffer( int nNewLength = -1 );
FreeExtra
void FreeExtra( );
LockBuffer
LPTSTR LockBuffer( );
UnlockBuffer
void UnlockBuffer( )
'Study > MFC' 카테고리의 다른 글
MFC 파일 입출력 (0) | 2011.09.28 |
---|---|
리스트 컨트롤에서 해당열을 클릭시 이벤트 처리 (0) | 2011.09.28 |
파일 정보 얻기!!!!!!~~~~ (0) | 2011.09.28 |
휴지통관련 API ~~ 굿이에요 굿굿!! (0) | 2011.09.28 |
CWinthread의 메모리릭.... (0) | 2011.09.06 |
댓글