티스토리 뷰

출처 : http://tory45.egloos.com/4897048



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 
AfxExtractSubString 

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

Header
: <afxwin.h>

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

Parameters

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

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

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

chSep
  • 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 oflpszFullString 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.


반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함