CString 의 멤버 함수인 Remove 와  Replace 의 활용 예이다.

Remove 함수는 문자열에서 지정된 문자를 삭제하고 Replace 는 문자열에서 지정된 문자 또는 문자열을 다를 문자나 문자열로 치환한다.
	strValue = _T("Hello World!!");

	int nCh = strValue.Replace( _T('l'), _T('w') );
	TRACE2( "Replaced %d : %s \r\n", nCh, strValue );

	nCh = strValue.Replace( _T("ww"), _T("ll") );
	TRACE2( "Replaced %d : %s \r\n", nCh, strValue );

	nCh = strValue.Remove( _T('!') );
	TRACE2( "Removed %d : %s \r\n", nCh, strValue );

#결과
Replaced 3 : Hewwo Worwd!! 
Replaced 1 : Hello Worwd!! 
Removed 2 : Hello Worwd 

MSDN 사이트에서 발췌한 Replace 사용 예.
http://msdn.microsoft.com/en-us/library/aa300582(VS.60).aspx
//First example, with old and new equal in length.

CString strZap("C--");
int n = strZap.Replace('-', '+');
ASSERT(n == 2);
ASSERT(strZap == "C++");

//Second example, old and new are of different lengths.

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  golf");

// note that you now have an extra space in your
// sentence. To remove the extra space, include it
// in the string to be replaced, i.e.,"ice ".

MSDN 사이트에서 발췌한 Remove 사용 예.
http://msdn.microsoft.com/en-us/library/aa300579(VS.60).aspx
//remove the lower-case letter 't' from a sentence:

CString str("This is a test.");
int n = str.Remove('t');
ASSERT(n == 2);
ASSERT(str == "This is a es.");
Posted by NeoDreamer
:
BLOG main image
사람의 발목을 잡는건 '절망'이 아니라 '체념'이고 앞으로 나아가게 하는건 '희망'이 아니라 '의지'다. - 암스 중에서 - by NeoDreamer

공지사항

카테고리

전체보기 (793)
Life Story (1)
Thinking (2)
Nothing (5)
---------------* (0)
Dev Story (701)
Com. Story (80)
IT Story (1)
---------------+ (0)
Etc (2)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

Total :
Today : Yesterday :
05-06 00:16