本文整理汇总了C++中std::wstring::replace方法的典型用法代码示例。如果您正苦于以下问题:C++ wstring::replace方法的具体用法?C++ wstring::replace怎么用?C++ wstring::replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::wstring
的用法示例。
在下文中一共展示了wstring::replace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PutArg
//-----------------------------------------------------------------------------
void mglParser::PutArg(std::wstring &str, bool def)
{
size_t pos = str.find('$',def?10:0);
while(pos<str.length())
{
wchar_t ch = str[pos+1];
if(ch>='0' && ch<='9') str.replace(pos,2,par[ch-'0']);
else if(ch>='a' && ch<='z') str.replace(pos,2,par[ch-'a'+10]);
else if(ch=='$') str.replace(pos,2,L"\uffff");
else str.replace(pos,1,L"\uffff");
pos = str.find('$',def?10:0);
}
while((pos = str.find(L'\uffff'))<str.length()) str[pos]='$';
}
示例2: ReplaceMeasures
/*
** Replaces %1, %2 etc with the corresponding measure value
*/
bool CMeter::ReplaceMeasures(const std::vector<std::wstring>& stringValues, std::wstring& str)
{
bool replaced = false;
if (str.find(L'%') != std::wstring::npos)
{
WCHAR buffer[64];
// Create the actual text (i.e. replace %1, %2, .. with the measure texts)
for (size_t i = stringValues.size(); i > 0; --i)
{
size_t len = _snwprintf_s(buffer, _TRUNCATE, L"%%%i", (int)i);
size_t start = 0, pos;
do
{
pos = str.find(buffer, start, len);
if (pos != std::wstring::npos)
{
str.replace(pos, len, stringValues[i - 1]);
start = pos + stringValues[i - 1].length();
replaced = true;
}
}
while (pos != std::wstring::npos);
}
}
return replaced;
}
示例3: ReplaceMeasures
/*
** Replaces %1, %2, ... with the corresponding measure value.
**
*/
bool Meter::ReplaceMeasures(std::wstring& str, AUTOSCALE autoScale, double scale, int decimals, bool percentual)
{
bool replaced = false;
if (str.find(L'%') != std::wstring::npos)
{
WCHAR buffer[64];
for (size_t i = m_Measures.size(); i > 0; --i)
{
size_t len = _snwprintf_s(buffer, _TRUNCATE, L"%%%i", (int)i);
size_t start = 0, pos;
const WCHAR* measureValue = m_Measures[i - 1]->GetStringOrFormattedValue(
autoScale, scale, decimals, percentual);
const size_t measureValueLen = wcslen(measureValue);
do
{
pos = str.find(buffer, start, len);
if (pos != std::wstring::npos)
{
str.replace(pos, len, measureValue, measureValueLen);
start = pos + measureValueLen;
replaced = true;
}
}
while (pos != std::wstring::npos);
}
}
return replaced;
}
示例4: ReplaceWString
void ReplaceWString(std::wstring & str, const std::wstring & find, const std::wstring & replace)
{
for(auto i = str.find(find); i != std::wstring::npos ;i = str.find(find))
{
str.replace(i, find.size(), replace);
}
}
示例5: string_replace_all
std::wstring string_replace_all( std::wstring src, std::wstring const& target, std::wstring const& repl){
if (target.length() == 0) {
// searching for a match to the empty string will result in
// an infinite loop
// it might make sense to throw an exception for this case
return src;
}
if (src.length() == 0) {
return src; // nothing to match against
}
size_t idx = 0;
for (;;) {
idx = src.find( target, idx);
if (idx == std::wstring::npos) break;
src.replace( idx, target.length(), repl);
idx += repl.length();
}
return src;
}
示例6: ReplaceString
void ReplaceString(std::wstring& input, const std::wstring placeholder, const std::wstring replacement)
{
size_t replaceStart = input.find(placeholder);
if (replaceStart != std::string::npos)
{
input.replace(replaceStart, placeholder.length(), replacement);
}
}
示例7: ReplaceAll
static void ReplaceAll(std::wstring& str, const std::wstring& from, const std::wstring& to)
{
size_t start_pos = 0;
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length();
}
}
示例8: replaceStringInPlace
static void replaceStringInPlace(std::wstring& subject, const std::wstring& search,
const std::wstring& replace) {
size_t pos = 0;
while ((pos = subject.find(search, pos)) != std::wstring::npos) {
subject.replace(pos, search.length(), replace);
pos += replace.length();
}
}
示例9: replaceAll
void StringUtil::replaceAll(std::wstring& src, const std::wstring& from, const std::wstring to) {
size_t pos = 0;
while((pos = src.find(from, pos)) != std::wstring::npos) {
src.replace(pos, from.length(), to);
pos += to.length();
}
}
示例10: replaceAll
void replaceAll(std::wstring& str, const std::wstring& from, const std::wstring& to) {
if(from.empty())
return;
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::wstring::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
}
}
示例11: ReplaceCharWithString
std::wstring ReplaceCharWithString(std::wstring source, const wchar_t replaceChar, std::wstring replaceString)
{
size_t posn = source.find(&replaceChar);
while (posn != std::wstring::npos)
{
source.replace(posn, 1, replaceString);
posn = source.find(&replaceChar, posn + replaceString.length());
}
return source;
}
示例12: ReplaceStringInplace
void ReplaceStringInplace(std::wstring& str, const wchar_t* search, const wchar_t* replace) {
size_t search_length = wcslen(search);
size_t replace_length = wcslen(replace);
size_t pos = 0;
while ((pos = str.find(search, pos)) != std::wstring::npos) {
str.replace(pos, search_length, replace);
pos += replace_length;
}
}
示例13: string_replace
void string_replace(std::wstring& strBig, const std::wstring & strsrc, const std::wstring &strdst)
{
std::wstring::size_type pos = 0;
while ((pos = strBig.find(strsrc, pos)) != std::wstring::npos)
{
strBig.replace(pos, strsrc.length(), strdst);
pos += strdst.length();
}
}
示例14: ReplaceMouseVariables
void Mouse::ReplaceMouseVariables(std::wstring& result) const
{
// Check for new-style variables: [$MOUSEX]
m_Skin->GetParser().ParseVariables(result, ConfigParser::VariableType::Mouse, m_Meter);
// Check for old-style variables: $MOUSEX$
size_t start = 0, end;
bool loop = true;
do
{
start = result.find(L'$', start);
if (start != std::wstring::npos)
{
size_t si = start + 1;
end = result.find(L'$', si);
if (end != std::wstring::npos)
{
size_t ei = end - 1;
if (si != ei && result[si] == L'*' && result[ei] == L'*')
{
result.erase(ei, 1);
result.erase(si, 1);
start = ei;
}
else
{
std::wstring strVariable = result.substr(si, end - si);
std::wstring value = m_Skin->GetParser().GetMouseVariable(strVariable, m_Meter);
if (!value.empty())
{
// Variable found, replace it with the value
result.replace(start, end - start + 1, value);
start += value.length();
}
else
{
start = end;
}
}
}
else
{
loop = false;
}
}
else
{
loop = false;
}
}
while (loop);
}
示例15: ReplaceString
int install_util::ReplaceString(std::wstring& src_str, const std::wstring& old_str, const std::wstring& new_str)
{
int count = 0;
std::wstring::size_type old_str_len = old_str.length(), new_str_len = new_str.length();
std::wstring::size_type pos = 0;
while ((pos = src_str.find(old_str, pos)) != std::wstring::npos)
{
src_str.replace(pos, old_str_len, new_str);
pos += new_str_len;
++count;
}
return count;
}