Exemple #1
0
//
// Replace all occurrences of the string szOld with szNew
//
WString WString::Replace ( const wchar_t* szOld, const wchar_t* szNew, bool bSearchJustReplaced ) const
{
    // Check if anything to replace first
    size_t idx = 0;
    if( ( idx = this->find ( szOld, idx ) ) == npos )
        return *this;

    size_t iOldLength = wcslen ( szOld );
    size_t iNewLength = wcslen ( szNew );
    WString strResult = *this;
    do
    {
        strResult.replace ( idx, iOldLength, szNew );
        if ( !bSearchJustReplaced )
            idx += iNewLength;
    }
    while( ( idx = strResult.find ( szOld, idx ) ) != npos );
    return strResult;
}