This code works perfect for string replacement, but it is case sensitive, which is what I need it to be:
WCHAR *StringReplaceEx(CONST WCHAR *orig, CONST WCHAR * pattern, CONST WCHAR *repl, WCHAR *sOut)
{
wstring wsoriginal = orig;
wstring wspatterntofind = pattern;
wstring wsreplacement = repl;
wstring wsOut = string_replace(wsoriginal, wspatterntofind, wsreplacement);
StringCchCopy(sOut, wcslen(wsOut.c_str())+1, wsOut.c_str());
return sOut;
}
wstring string_replace( wstring src, wstring const& target, wstring const& repl)
{
if ((target.length() == 0) || (src.length() == 0))
return src;
size_t idx = 0;
for (;;)
{
idx = src.find( target, idx);
if (idx == wstring::npos)
break;
src.replace( idx, target.length(), repl);
idx += repl.length();
}
return src;
}
This works excellently, but only if the string cases match.
Is there a way to do a case-insensitive replacement?
question from:
https://stackoverflow.com/questions/65919899/how-to-use-wstring-find-replace-for-a-case-insensitve-replacement 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…