如何替换 CCString?

How to Replace a CCString?

有没有类似于CCString的字符串替换方法?类似的东西需要另外 2 个 CCString 参数,将第一个与第二个

切换

不行,需要像下面这样自己实现

#include <string>

using std::string;

CCString* replaceCCString(CCString* cs, const CCString* csearch, const CCString* creplace)
{
    string s = cs->getCString();
    string search = csearch->getCString();
    string replace = creplace->getCString();

    for (size_t pos = 0; ; pos += replace.length()) {
        pos = s.find(search, pos);
        if (pos == string::npos)
            break;

        s.erase(pos, search.length());
        s.insert(pos, replace);
    }

    return CCString::create(s);
}