c++ - 如何检查某个字母或短语的字符串 vector ?

标签 c++

我在 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/

相关文章:

c++ - ENet c++ 库的最大数据包大小

c++ - 将范围添加到函数调用

c++ - 可以从指向成员函数模板参数的指针推导出类类型吗

c++ - 使用流读取C++中的可变长度输入

c++ - 无窗口 OpenGL

c++ - 指针变量大小

c# - FMOD,每秒节拍

c++ - 可能的 ComputeCPP SYCL 错误读取嵌套缓冲区

c++ - 设置运行时刻bitset的大小

c++ - 提升图形库 : possible to combine Bundled Properties with Interior Properties?