【发布时间】:2017-10-11 17:57:04
【问题描述】:
我必须在指定范围内搜索特定字符的字符串。我做的代码如下:
str.erase(str.begin(), str.begin()+5);
str.erase(str.begin() + 9, str.end()); // The range to be searched has been specified ie 5th index to 9th index
if( str.find('a') != string::npos){
cout << "YES, it exists" << endl;
}else{
cout << "No, it doesnt" << endl;
}
上面的代码按预期工作,但我很想知道是否有标准库函数可以完成这项工作。(可能在一行中)
【问题讨论】:
-
您从字符串中删除字符。 “//指定要搜索的范围”是什么意思?