c++ - 如何使用 wstring 查找/替换进行不区分大小写的替换?
问题描述
这段代码非常适合字符串替换,但它区分大小写,这就是我需要的:
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;
}
这非常有效,但前提是字符串大小写匹配。
有没有办法进行不区分大小写的替换?
解决方案
通过使用 boost,即使它超出了问题的范围,也为我解决了这个问题。
推荐阅读
- c# - 如何使用谷歌云视觉和统一使用移动相机识别文本?
- regex - 从文本框中获取字符串并放入可变数组
- kotlin - Kapt 不处理 micronaut-predator-processor
- wordpress - wordpress 商店重定向到哪里?
- c# - C#项目没有为自己写的c++ dll定义入口点
- ios - 在attributeText中添加链接修饰符后,范围内的文本变得不可见
- r - 您如何从世界银行 API 将多个指标下载到 R 中的单独列中?
- reactjs - Webpack dist 文件夹无法运行项目
- linux - 使用 docker - su 的身份验证失败
- java - Cplex If-then 二进制约束不更新