例如:char *ch="*******Content-Type:**********\r\n*****";
如何查找"Content-Type:"和"\r\n"之间的字符串;
请给代码,谢谢!

解决方案 »

  1.   

    char *ch= "*******Content-Type:**********\r\n*****"; 
    CString str = ch;
    int iST = str.Find("Content-Type");
    str = str.Right(str.GetLength() - iST - 12);
    int iED = str.Find("\r\n");
    str = str.Left(iED);
      

  2.   

    用strstr函数可以查出字符串首次出现的位置。
      

  3.   


    CString str1("Content-Type:");
    CString str2("\r\n");CString str("*******Content-Type:**********\r\n*****");int nStart = str.Find( str1 ) + str1.GetLength();
    int nEnd = str.Find( str2 );CString strResult = str.Mid( nStart, nEnd-nStart);
    原理:1、求出"Content-Type:"的长度;
    2、求出"Content-Type:"在字符串中的位置;
    3、以上两个值加起来就是开始取代位置;
    4、求出"\r\n"在字符串中的位置;
    5、截取需要的字符串。