Dev/C, C++

문자열 분할시, 특정 번째 문자열 얻기

newtype 2003. 7. 18. 17:31
제목이 어렵네요.. ㅡㅡ;
소스 보시면 어려운것 없으니 금방 이해 하실겁니다.
좋은 시간 되세요..^^


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

//--------------------------------------------------------------------------//
//Fuction        : Splite
//Parameter : LPTSTR lpszDest, LPCTSTR lpcszSorc, TCHAR cSep, int nIndex
//Return        : LPCTSTR
//Note                : lpcszSorc를 cSep로 나누어서 nIndex번째 문자열을 lpszDest에 넣는다.
//--------------------------------------------------------------------------//
LPCTSTR Splite( LPTSTR lpszDest, LPCTSTR lpcszSorc, TCHAR cSep, int nIndex)
{
       int i, j, k, l;
       int count;

       count = (int)strlen(lpcszSorc);
       for (i=j=k=l=0; i<count && l<=nIndex; i++)
       {
               if ( *(lpcszSorc+i) == cSep )
               {
                       k=i;
                       strncpy( lpszDest, lpcszSorc+j, k-j );
                       lpszDest[k-j] = 0;
                       j=k+1;
                       l++;
               }
       }

       return lpszDest;
}
반응형