字符串查找之c++

#include "stdafx.h"
#include<string>
#include<iostream>
using std::string;
using std::cout;
using std::endl;




int _tmain(int argc, _TCHAR* argv[])
{
	string strResource = "123456789";
	string strFind1 = "15", strFind2="23", strFind3="a2";
	
	string::size_type pos = string::npos;
	//搜索strFind1在strResource第一次出现的位置
	pos = strResource.find(strFind1);

	//搜索从下标=1开始,strFind1在strResource第一次出现的位置
	pos = strResource.find(strFind1,1);

	//搜索strFind2最后一次在strResource中出现的位置
	pos = strResource.rfind(strFind2);

	//搜索从下标=1开始,strFind2最后一次在strResource中出现的位置
	pos = strResource.rfind(strFind2, 1);

	//搜索strFind3或strFind3中部分字符串在strResource中第一次出现的位置
	pos = strResource.find_first_of(strFind3);

	//搜索从下标=1开始,strFind3或strFind3中部分字符串在strResource中第一次出现的位置
	pos = strResource.find_first_of(strFind3,1);

	//搜索strFind3或strFind3中部分字符串在strResource中最后一次出现的位置
	pos = strResource.find_last_of(strFind3);

	//搜索从下标=1开始,strFind3或strFind3中部分字符串在strResource中最后一次出现的位置
	pos = strResource.find_last_of(strFind3,1);

	//搜索第一个不存在于strFind3的字符的位置
	pos = strResource.find_first_not_of(strFind3);

	//搜索从下标=1开始,第一个不存在于strFind3的字符的位置
	pos = strResource.find_first_not_of(strFind3,1);

	//搜索到下标=strResource.length()结束,最后一个不存在于strFind3的字符的位置
	pos = strResource.find_last_not_of(strFind3,strResource.length());

	//搜索到下标=2结束,最后一个不存在于strFind3的字符的位置
	pos = strResource.find_last_not_of(strFind3,2);

	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值