strreplace problem
#1

Why does this strreplace(path, " ", "_"); give me an error error 035: argument type mismatch (argument 2)

stock strreplace(string[], find, replace)
{
for(new i=0; string[i]; i++)
{
if(string[i] == find)
{
string[i] = replace;
}
}
}

Basically wanna check if there's space and replace it with "_"
Reply
#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
#3

Of course, my bad, sorry. Edited the post
Guess i was a bit too lazy there, lol.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)