CString을 이용한 초초 간단 Token 처리( MFC Library ) ▶Dev Talk

MFC 프로그램 처리시 가끔 문자열에 대해 Token 처리해야 하는 경우가 발생합니다. 이때 token을 위한 buf를 만들고 해제하는 과정이 아주 귀찮습니다.. 이때 사용할수 있는 초 간단 Token 처리 API입니다.

CString strOrg;
CString strTok_1;
CString strTok_2;
CString strTok_3;

strOrg.Format("%s", "123$456$789");

AfxExtractSubString( strTok_1, strOrg, 0, '$');
AfxExtractSubString( strTok_2, strOrg, 1, '$');
AfxExtractSubString( strTok_3, strOrg, 2, '$');

strTok_1에는 "123"이
strTok_2에는 "456"이
strTok_3에는 "789"가 대입됩니다..

참조 : http://msdn.microsoft.com/en-us/library/aa991543(VS.80).aspx

MFC Library Reference 

This global function can be used to extract a substring from a given source string.

: <afxwin.h>

BOOL AFXAPI AfxExtractSubString (
   CString& rString,
   LPCTSTR lpszFullString,
   int iSubString,
   TCHAR chSep = '\n'


  • Reference to a CString object that will receive an individual substring.

  • String containing the full text of the string to extract from.

  • Zero-based index of the substring to extract from lpszFullString.

  • Separator character used to delimit substrings.

TRUE if the function successfully extracted the substring at the provided index; otherwise, FALSE.

This function is useful for extracting multiple substrings from a source string when a known single character separates each substring. This function searches from the beginning of the lpszFullString parameter each time it is called.

This function will return FALSE if either lpszFullString is set to NULL or the function reaches the end of lpszFullString without finding iSubString+1 occurrences of the specified separator character. The rString parameter will not be modified from its original value if lpszFullString was set to NULL; otherwise, the rString parameter is set to the empty string if the substring could not be extracted for the specified index.



  • 허원석 2009/05/26 11:48 # 삭제 답글

    감사... 구글에서 검색했습니다. CString token
  • dinga 2009/06/01 20:27 # 삭제 답글

    좋은 정보 감사드립니다.
  • 토리 2009/06/02 17:45 # 답글

댓글 입력 영역


free counters