本文整理汇总了C++中STRING::replace方法的典型用法代码示例。如果您正苦于以下问题:C++ STRING::replace方法的具体用法?C++ STRING::replace怎么用?C++ STRING::replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类STRING
的用法示例。
在下文中一共展示了STRING::replace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: StrReplace
/**
* string replace function
* @param string str need op string
* @param string old_str need replace old string
* @param string new_str need replace to new string
*/
STRING CCUtil::StrReplace( STRING str, STRING search_str, STRING replace_str )
{
STRING::size_type pos = 0 ;
while( ( pos = str.find( search_str, pos ) ) != STRING::npos )
{
str.replace( pos, search_str.size(), replace_str ) ;
pos++ ;
}
return str ;
}
示例2: ReplaceToSign_Normal
VOID CStringFilter::ReplaceToSign_Normal(const STRING& strIn, STRING& strOut)
{
static STRING strSign = "?";
static BYTE byANSIBegin = 0X20;
static BYTE byANSIEnd = 0X80;
strOut = strIn;
STRING::size_type allsize = m_vIncluce.size();
//包含替换
for(STRING::size_type i = 0; i < m_vIncluce.size(); ++i)
{
STRING::size_type pos = strIn.find(m_vIncluce[i]);
while(STRING::npos != pos)
{
STRING strReplace = "";
STRING::size_type len = m_vIncluce[i].size();
//如果包含替换的是1个字节的ANSI字节,替换前,
//需要确认前一个字节一定不是双字节字符集的前一个字节
BOOL bSkip = FALSE;
if(1 == len && pos > 0)
{
BYTE byChar = strIn[pos-1];
#if 0
char dbgmsg[256];
_snprintf(dbgmsg, 255, "strIn[pos-1]:0x%X(0x%X)\n", strIn[pos-1],byChar);
::OutputDebugString(dbgmsg);
#endif
//不是标准ANSI英文字符
if(!(byChar >= byANSIBegin && byChar <= byANSIEnd || byChar == '\r' || byChar == '\n' || byChar == '\t'))
{
bSkip = TRUE;
}
}
if(!bSkip)
{
for(STRING::size_type k = 0; k < len; ++k, strReplace += strSign);
strOut.replace(pos, len, strReplace);
}
pos = strIn.find(m_vIncluce[i], pos+len);
}
}
//完全匹配替换
if(IsFullCmp(strIn))
{
STRING::size_type len = strIn.size();
strOut.clear();
for(STRING::size_type i = 0; i < len; ++i, strOut += strSign);
}
}
示例3: ReplaceToSign_New
VOID CStringFilter::ReplaceToSign_New(const STRING& strIn, STRING& strOut)
{
static STRING strSign = "~$%^&(){}`-_+=?,.<>";
strOut = strIn;
STRING::size_type allsize = m_vIncluce.size();
//包含替换
for(STRING::size_type i = 0; i < m_vIncluce.size(); ++i)
{
STRING::size_type pos = strIn.find(m_vIncluce[i]);
while(STRING::npos != pos)
{
STRING strReplace = "";
STRING::size_type len = m_vIncluce[i].size();
for(STRING::size_type k = 0; k < len; ++k)
{
STRING::size_type ri = rand()%int(strSign.size());
strReplace += strSign.at(ri);
}
strOut.replace(pos, len, strReplace);
pos = strIn.find(m_vIncluce[i], pos+len);
}
}
//完全匹配替换
if(IsFullCmp(strIn))
{
STRING::size_type len = strIn.size();
strOut.clear();
for(STRING::size_type i = 0; i < len; ++i)
{
STRING::size_type ri = rand()%int(strSign.size());
strOut += strSign.at(ri);
}
}
}