[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppStringReplace
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppStringReplace
(C++) Replace substrings of a std::string by other std::strings
std::string replaceOnce( std::string result, const std::string& replaceWhat, const std::string& replaceWithWhat) { const int pos = result.find(replaceWhat); if (pos==-1) return result; result.replace(pos,replaceWhat.size(),replaceWithWhat); return result; }
- include <string>
std::string replaceAll(
std::string result,
const std::string& replaceWhat,
const std::string& replaceWithWhat)
{
while(1)
{
const int pos = result.find(replaceWhat);
if (pos==-1) break;
result.replace(pos,replaceWhat.size(),replaceWithWhat);
}
return result;
}
'Replace substrings of a string by other strings' links
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
