AMX Mod X API Documentation

Signature
stock xs_replace(text[], len, const what[], const with[]){ new occur = 0; new i = 0; new bufPos = 0; new replaceLen = strlen(with); new whatLen = strlen(what); for(; text[i]; ++i) { if(text[i] == what[0]) { new posInWhat=0; new j; for(j = i; j-i < replaceLen && text[j]; ++j, ++posInWhat) { if(text[j] != what[posInWhat]) break; } if(whatLen == posInWhat) { for(new i2 = 0; i2 < replaceLen && bufPos < XS_REPLACEBUF_SIZE; ++i2) xs__replace_buf[bufPos++] = with[i2]; i = j - 1; ++occur; if(bufPos >= XS_REPLACEBUF_SIZE) return occur; continue; } } if(bufPos >= XS_REPLACEBUF_SIZE) return occur; xs__replace_buf[bufPos++] = text[i]; } xs__replace_buf[bufPos] = 0; copy(text, len, xs__replace_buf); return occur;}
Description

Replaces all occurencies of @what in @text with @with.

Parameters
  • text The text to search in.
  • len The maximum size of the @text buffer.
  • what What to search for.
  • with What to replace occurencies with.
Returns

Returns the number of replaced items.

Назад
Верх