相关疑难解决方法(0)

如何删除C++ std :: string中的重音和波形符号

我在C++中有一个字符串的问题,它有几个西班牙语单词.这意味着我有很多带有重音符号和波浪号的单词.我想替换他们没有重音的同行.示例:我想替换这个词:哈比亚的"había".我尝试直接替换它,但使用字符串类的替换方法,但我无法让它工作.

我正在使用此代码:

for (it= dictionary.begin(); it != dictionary.end(); it++)
{
    strMine=(it->first);
    found=toReplace.find_first_of(strMine);
    while (found!=std::string::npos)
    {
        strAux=(it->second);
        toReplace.erase(found,strMine.length());
        toReplace.insert(found,strAux);
        found=toReplace.find_first_of(strMine,found+1);
    }
}
Run Code Online (Sandbox Code Playgroud)

dictionary这样的地图在哪里(有更多条目):

dictionary.insert ( std::pair<std::string,std::string>("á","a") );
dictionary.insert ( std::pair<std::string,std::string>("é","e") );
dictionary.insert ( std::pair<std::string,std::string>("í","i") );
dictionary.insert ( std::pair<std::string,std::string>("ó","o") );
dictionary.insert ( std::pair<std::string,std::string>("ú","u") );
dictionary.insert ( std::pair<std::string,std::string>("ñ","n") );
Run Code Online (Sandbox Code Playgroud)

toReplace字符串是:

std::string toReplace="á-é-í-ó-ú-ñ-á-é-í-ó-ú-ñ";
Run Code Online (Sandbox Code Playgroud)

我显然必须遗漏一些东西.我无法弄清楚.有没有我可以使用的图书馆?

谢谢,

c++ string text str-replace

15
推荐指数
2
解决办法
2万
查看次数

标签 统计

c++ ×1

str-replace ×1

string ×1

text ×1