user-0 提问: Cstring 字符串截取

回复:
user: user-0
content: 非常感谢Mr.zhang的例子，已收藏，我使用以下的方法搞定了，因为要要找很多“T19#。。。。。。#”使用Tokenize+token+for循环 CArray<CString> V; 	TCHAR *token; 	TCHAR seps[]   = L"#"; 	TCHAR *data=szData.GetBuffer(); 	token = _tcstok( data, seps );  	while( token != NULL ) 	{  		V.Add(token);  		token = _tcstok( NULL, seps );  	}  	int size=V.GetSize(); 	size=V.GetSize();  	for(int i=0;i<size;i++) 	{ 		if(V.GetAt(i).Find(L"0")!=-1) 		{ 		int uPos1 = 0; 		CString sn= V.GetAt(i).Tokenize(L",",uPos1).Trim(); 		CString result= V.GetAt(i).Tokenize(L",",uPos1).Trim(); 	}

user: user-1
content: 引用 1 楼 user-2 的回复:CString好像有Find方法，查找"T19#"再结合Mid方法就可以取出需要的字串了 CString::Find  int Find( TCHAR ch ) const;  int Find( LPCTSTR lpszSub ) const;  int Find( TCHAR ch, int nStart ) const;  int Find( LPCTSTR pstr, int nStart ) const;  Return Value  The zero-based index of the first character in this CString object that matches the requested substring or characters; -1 if the substring or character is not found.  Parameters  ch  A single character to search for.  lpszSub  A substring to search for.  nStart  The index of the character in the string to begin the search with, or 0 to start from the beginning. The character at nStart is excluded from the search if nStart is not equal to 0.  pstr  A pointer to a string to search for.  Remarks  Searches this string for the first match of a substring. The function is overloaded to accept both single characters (similar to the run-time function strchr) and strings (similar to strstr).  Example  // First example demonstrating  // CString::Find ( TCHAR ch ) CString s( "abcdef" ); ASSERT( s.Find( 'c' ) == 2 ); ASSERT( s.Find( "de" ) == 3 );  // Second example demonstrating  // CString::Find( TCHAR ch, int nStart ) CString str("The stars are aligned"); int n = str.Find('e', 5); ASSERT(n == 12);  CString Overview |  Class Members |  Hierarchy Chart  See Also   CString::ReverseFind, CString::FindOneOf   CString::Mid  CString Mid( int nFirst ) const; throw( CMemoryException );  CString Mid( int nFirst, int nCount ) const; throw( CMemoryException );  Return Value  A CString object that contains a copy of the specified range of characters. Note that the returned CString object may be empty.   Parameters  nFirst  The zero-based index of the first character in this CString object that is to be included in the extracted substring.  nCount  The number of characters to extract from this CString object. If this parameter is not supplied, then the remainder of the string is extracted.  Remarks  Extracts a substring of length nCount characters from this CString object, starting at position nFirst (zero-based). The function returns a copy of the extracted substring. Mid is similar to the Basic MID$ function (except that indexes are zero-based).  For multibyte character sets (MBCS), nCount refers to each 8-bit character; that is, a lead and trail byte in one multibyte character are counted as two characters.  Example  The following example demonstrates the use of CString::Mid.  // example for CString::Mid CString s( _T("abcdef") ); ASSERT( s.Mid( 2, 3 ) == _T("cde") );  CString Overview |  Class Members |  Hierarchy Chart  See Also   CString::Left, CString::Right

user: user-2
content: CString好像有Find方法，查找"T19#"再结合Mid方法就可以取出需要的字串了