Created
June 14, 2017 09:10
-
-
Save utilForever/fdf1540cea0de65cfc0a1a69d8cafb63 to your computer and use it in GitHub Desktop.
Replace some pattern in std::wstring with another pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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