strreplace problem
#2

Use this:

pawn Код:
stock str_replace(sSearch[], sReplace[], const sSubject[], &iCount = 0)
{
    new
        iLengthTarget = strlen(sSearch),
        iLengthReplace = strlen(sReplace),
        iLengthSource = strlen(sSubject),
        iItterations = (iLengthSource - iLengthTarget) + 1;

    new
        sTemp[128],
        sReturn[_strlib_med_string];

    strcat(sReturn, sSubject, _strlib_med_string);
    iCount = 0;

    for(new iIndex; iIndex < iItterations; ++iIndex)
    {
        strmid(sTemp, sReturn, iIndex, (iIndex + iLengthTarget), (iLengthTarget + 1));

        if(!strcmp(sTemp, sSearch, false))
        {
            strdel(sReturn, iIndex, (iIndex + iLengthTarget));
            strins(sReturn, sReplace, iIndex, iLengthReplace);

            iIndex += iLengthTarget;
            iCount++;
        }
    }

    return sReturn;
}
Arguments:
sSearch[]: String to search for
sReplace[]: String to replace with
sSubject[]: Original string
&iCount: How many times 'sSearch' has been replaced. (optional)

Код:
str_replace(" ", "_", path);
Source: https://sampforum.blast.hk/showthread.php?tid=85697
Reply


Messages In This Thread
strreplace problem - by NoteND - 11.01.2019, 13:26
Re: strreplace problem - by Macronix - 11.01.2019, 13:39
Re: strreplace problem - by Macronix - 11.01.2019, 13:54

Forum Jump:


Users browsing this thread: 1 Guest(s)