Программирование в IIS


Пример 5.9

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Name: FindAndReplace

In: psContainer - pointer to a string that will be searched and edited if a value is discovered. psTarget - pointer to a string that is being sought for replacement. psReplacement - pointer to a string that will replace the the string pointed to in psTarget.

Out: nothing - but psContainer will be changed

Purpose: searches string psContainer pointer for the string that psTarget points to and replaces it with the string that psReplacement points to.

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ void FindAndReplace(string *psContainer, string *psTarget, string *psReplacement) {

string::size_type idx; idx = psContainer->find(*psTarget); while (idx != string::npos)//an instance was found { //are we at the end of the string if (psContainer->size() == idx) { *psContainer += *psReplacement; break; } else { psContainer->replace (idx, psTarget->size() , *psReplacement);

//advance beyond the current character idx += psReplacement->size(); }

//look for next occurance idx = psContainer->find(*psTarget, idx); }


Листинг 5.9.

Закрыть окно

Содержание  Назад  Вперед