当前位置: 首页>>代码示例>>C++>>正文


C++ wstring::replace方法代码示例

本文整理汇总了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]='$';
}
开发者ID:nickjhathaway,项目名称:mathgl,代码行数:15,代码来源:parser.cpp

示例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;
}
开发者ID:RichVRed,项目名称:rainmeter,代码行数:32,代码来源:Meter.cpp

示例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;
}
开发者ID:Rivolvan,项目名称:rainmeter,代码行数:37,代码来源:Meter.cpp

示例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);
    }
}
开发者ID:blaquee,项目名称:x64dbgpatchexporter,代码行数:7,代码来源:pluginmain.cpp

示例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;
}
开发者ID:Jstd,项目名称:Jstd-Bootstrap,代码行数:25,代码来源:transformers.cpp

示例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);
  }
}
开发者ID:dfhljf,项目名称:adblockplusie,代码行数:8,代码来源:Utils.cpp

示例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();
    }
}
开发者ID:cloudbase,项目名称:PyMI,代码行数:8,代码来源:MI++.cpp

示例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();
    }
}
开发者ID:xcodez,项目名称:jsfs,代码行数:8,代码来源:FileSystemServiceImpl.cpp

示例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();
	}
}
开发者ID:gvsurenderreddy,项目名称:openulteo,代码行数:8,代码来源:StringUtil.cpp

示例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'
    }
}
开发者ID:sundetova,项目名称:kaz-eng-generalisation,代码行数:9,代码来源:apertium-add-restrictions-to-sl.C

示例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; 
}
开发者ID:conachang,项目名称:mylyn.incubator,代码行数:10,代码来源:Windows7SearchProvider.cpp

示例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;
        }
    }
开发者ID:Kingwl,项目名称:libwtfdanmaku,代码行数:10,代码来源:StringUtils.cpp

示例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();
	}

}
开发者ID:wiSCADA,项目名称:XHService,代码行数:11,代码来源:xhservice.cpp

示例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);
}
开发者ID:TheAzack9,项目名称:rainmeter,代码行数:53,代码来源:Mouse.cpp

示例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;
}
开发者ID:510908220,项目名称:setup,代码行数:13,代码来源:install_util.cpp


注:本文中的std::wstring::replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。