MFC中
如何编程判断字符串A是否是字符串B的一部分
并取得字符串B中首次出现字符串A的位置

解决方案 »

  1.   

    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);
      

  2.   

    CString strA = "cde", strB = "abcdef";
    int nIndex = 0;

    if( (nIndex = strB.Find(strA)) != -1)
    {
    CString strTemp;
    strTemp.Format("%d", nIndex);
    AfxMessageBox(strTemp);
    }