CString 의 멤버 함수인 Remove 와 Replace 의 활용 예이다.
Remove 함수는 문자열에서 지정된 문자를 삭제하고 Replace 는 문자열에서 지정된 문자 또는 문자열을 다를 문자나 문자열로 치환한다.
MSDN 사이트에서 발췌한 Replace 사용 예.
http://msdn.microsoft.com/en-us/library/aa300582(VS.60).aspx
MSDN 사이트에서 발췌한 Remove 사용 예.
http://msdn.microsoft.com/en-us/library/aa300579(VS.60).aspx
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.");
'Dev Story > Tips' 카테고리의 다른 글
[STL] map 의 맨 마지막 원소에 접근하기 (map.end() 는 마지막 원소가 아니다!!) (0) | 2009.02.23 |
---|---|
TurboC++ Explorer 에서 Indy9 사용하기 (0) | 2009.02.14 |
실행시간에 툴바의 툴팁 바꾸기 (0) | 2009.02.03 |
[MFC] AfxFormatString1() 과 AfxFormatString2()를 이용한 파라메터 스트링의 활용 (0) | 2009.02.02 |
[MFC] 간단하게 부분 문자열을 추출하는 방법 - AfxExtractSubString() (0) | 2009.02.02 |