Инфо из string.inc:
/* Replaces a contained string iteratively.
* This ensures that no infinite replacements will take place by
* intelligently moving to the next string position each iteration.
*/
stock replace_all(string[], len, const what[], const with[])
{
new pos = 0;
if ((pos = contain(string, what)) == -1)
{
return 0;
}
new total = 0;
new with_len = strlen(with);
new diff = strlen(what) - with_len;
new total_len = strlen(string);
new temp_pos = 0;
while (replace(string[pos], len - pos, what, with) != 0)
{
/* jump to position after replacement */
pos += with_len;
/* update cached length of string */
total_len -= diff;
/* will the next call be operating on the last character? */
if (pos >= total_len)
{
break;
}
/* find the next position from our offset */
temp_pos = contain(string[pos], what);
/* if it's invalid, we're done */
if (temp_pos == -1)
{
break;
}
/* otherwise, reposition and update counters */
pos += temp_pos;
total++;
}
return total;
}
Синтаксис:
replace_all ( string[], len, what[], with[] )
- string[] - Строка в которой будут происходить замены
- len - Максимальная длинна строки
- what[] - Что заменить
- with[] - На что заменить
Тип функции:
stock
Пример:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "[string.inc] replace_all"
#define VERSION "1.0"
#define AUTHOR "Admin"
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_concmd("func_replace_all","func_replace_all")
}
public func_replace_all(){
new text[] = {"Its text for text replace"}
new what[] = {"text"}
new whith[] = {"MEGA"}
server_print("Test:%s",text)
replace_all(text,64,what,whith)
server_print("Test:%s",text)
}
Описание:
Функция по своей работе аналогична функции replace, но с существенным отличием, она ищет не одно точное совпадение в тексте, а все.
То есть если кто то написал слово P.L.U.G.I.N, то можно указать функции искать в тексте точки и заменять их на ничто ( тоесть просто удалить) тогда получится так PLUGIN.
Любое другое применение функции, зависит от вашей фантази.