我在 C++ 中有一个带有此 [Apples,Orangesandgrapes] 的字符串 vector ,现在我也想搜索 vector 而不是整个字符串,而是字符串中写着“andgrapes”的部分,我也想更改它, “没有葡萄”。所有只是一个例子。
在 Substring search interview question 上回答 抱歉,我没法说得更清楚。
最佳答案
我会使用 boost::replace_all为此:
#include <iostream>
#include <vector>
#include <string>
#include <boost/algorithm/string/replace.hpp>
int main()
{
std::vector<std::string> v = { "Apples", "Orangesandgrapes" };
for (auto & s : v)
{
boost::replace_all(s, "andgrapes", "nograpes");
std::cout << s << '\n';
}
}
关于c++ - 如何检查某个字母或短语的字符串 vector ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8973721/