如何查找字符串中某一段特定字符串 例如:char *ch="*******Content-Type:**********\r\n*****";如何查找"Content-Type:"和"\r\n"之间的字符串;请给代码,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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); 用strstr函数可以查出字符串首次出现的位置。 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、截取需要的字符串。 数字签名后的ActiveX控件能下载,但就是不让调用?为啥? 为嘛ListBox控件一直收不到LBN_SELCHANGE消息 vc操作excel如何获得当下选择的单元格地址? [求助]如何给DateTimePicker设置日期时间 寻找Microsoft开发者手册 请教VC入门问题 求CSocket源程序,在线等待,收到即给分 请教:为什么我的程序中字体显示总是旋转90度的? 关于改变鼠标图标的问题 哪位大虾知道如何修改注册表HKEY_CURRENT_USER项中别的用户的信息。 绘图问题的讨论 获取其它窗体应用程序中DataList或者DataGrid控件里的内容?
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);
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、截取需要的字符串。