【问题标题】:C++ Find and Replace String SIMPLEC++ 查找和替换字符串 SIMPLE
【发布时间】:2016-02-09 13:13:27
【问题描述】:

我需要一些东西来替换声明字符串中的文本。

像这样,但不是 Visual Basic,而是用 C++ 编写

Dim Projectile As String = "Content"
Projectile = Replace(Projectile, "Find", "Replace")`

或者像这样,但不是 C#,而是在 C++ 中

string Projectile; 
Projectile = Projectile.Replace("A", "B")

我需要一个简单的代码。如果您也可以提供多种选择,那就太好了。也非常感谢您对代码进行简要说明!

【问题讨论】:

  • 需要做的是拿起一本书。这不是代码编写服务。

标签: c++ replace find


【解决方案1】:

您可能会发现 boost::algorithm::replace_all (http://www.boost.org/doc/libs/1_41_0/doc/html/boost/algorithm/replace_all.html) 非常适合。

这是一个例子:

#include <boost/algorithm/string.hpp>
#include <iostream>

int main(int argc,char** argv)
{
    using namespace std;
    string test = "123456";
    boost::algorithm::replace_all(test,"123","456");
    cout << test << endl;
    return 0;
}

将输出:“456456”

【讨论】:

    猜你喜欢
    • 2011-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-13
    • 1970-01-01
    相关资源
    最近更新 更多