27.06.2011, 15:20
pawn Code:
stock strreplace (newstr [], oldstr [], srcstr [], deststr [], bool: ignorecase = false, size = sizeof (deststr))
{
new
newlen = strlen (newstr),
oldlen = strlen (oldstr),
srclen = strlen (srcstr),
idx,
rep;
for (new i = 0; i < srclen; ++i)
{
if ((i + oldlen) < srclen)
{
if (!strcmp (srcstr [i], oldstr, ignorecase, oldlen))
{
deststr [idx] = '\0';
strcat (deststr, newstr, size);
++rep;
idx += newlen;
i += oldlen - 1;
}
else
{
if (idx < size)
deststr [idx++] = srcstr [i];
else
return rep;
}
}
else
{
if (idx < size)
deststr [idx++] = srcstr [i];
else
return rep;
}
}
return rep;
}