Skip to content

Instantly share code, notes, and snippets.

@utilForever
Created June 14, 2017 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utilForever/fdf1540cea0de65cfc0a1a69d8cafb63 to your computer and use it in GitHub Desktop.
Save utilForever/fdf1540cea0de65cfc0a1a69d8cafb63 to your computer and use it in GitHub Desktop.
Replace some pattern in std::wstring with another pattern
std::wstring ReplaceWCSWithPattern(__in const std::wstring &message, __in const std::wstring &pattern, __in const std::wstring &replace)
{
std::wstring result = message;
std::wstring::size_type pos = 0;
std::wstring::size_type offset = 0;
while ((pos = result.find(pattern, offset)) != std::wstring::npos)
{
result.replace(result.begin() + pos, result.begin() + pos + pattern.size(), replace);
offset = pos + replace.size();
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment