Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to remove accents and tilde in a C++ std::string
    primarykey
    data
    text
    <p>I have a problem with a string in C++ which has several words in Spanish. This means that I have a lot of words with accents and tildes. I want to replace them for their not accented counterparts. Example: I want to replace this word: "había" for habia. I tried replace it directly but with replace method of string class but I could not get that to work.</p> <p>I'm using this code:</p> <pre><code>for (it= dictionary.begin(); it != dictionary.end(); it++) { strMine=(it-&gt;first); found=toReplace.find_first_of(strMine); while (found!=std::string::npos) { strAux=(it-&gt;second); toReplace.erase(found,strMine.length()); toReplace.insert(found,strAux); found=toReplace.find_first_of(strMine,found+1); } } </code></pre> <p>Where <code>dictionary</code> is a map like this (with more entries):</p> <pre><code>dictionary.insert ( std::pair&lt;std::string,std::string&gt;("á","a") ); dictionary.insert ( std::pair&lt;std::string,std::string&gt;("é","e") ); dictionary.insert ( std::pair&lt;std::string,std::string&gt;("í","i") ); dictionary.insert ( std::pair&lt;std::string,std::string&gt;("ó","o") ); dictionary.insert ( std::pair&lt;std::string,std::string&gt;("ú","u") ); dictionary.insert ( std::pair&lt;std::string,std::string&gt;("ñ","n") ); </code></pre> <p>and <code>toReplace</code> strings is:</p> <pre><code>std::string toReplace="á-é-í-ó-ú-ñ-á-é-í-ó-ú-ñ"; </code></pre> <p>I obviously must be missing something. I can't figure it out. Is there any library I can use?.</p> <p>Thanks,</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload