SA-MP Forums Archive
strreplace issue - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: strreplace issue (/showthread.php?tid=194440)



strreplace issue - Victor - 29.11.2010

I made a function called strreplace(its not the one from Dracoblue) when the string gets returned, it adds something to the front of the string.
I am currently using 0.3c RC1
The Code:
http://pastebin.com/m4TRN9Rs The testing and strreplace

The output:
Код:
[09:31:51] This is only a test, so don't ask!
[09:31:51] This is only a , so don't ask!
[09:31:51] This is only a foo, so don't ask!
[09:31:51] Ђ,xThis is only a foo, so don't ask!
Thanks for your help.


Re: strreplace issue - MadeMan - 29.11.2010

I tested this on a 0.3b version and have the same problem, only different symbols added.

Код:
This is only a test, so don't ask!
This is only a , so don't ask!
This is only a foo, so don't ask!
ЂШThis is only a foo, so don't ask!
I don't see anything wrong in the code.


Re: strreplace issue - MadeMan - 29.11.2010

If you use this code, it works.

pawn Код:
public OnFilterScriptInit()
{
    new string[128];
    format(string, sizeof(string), "This is only a test, so don't ask!");
    printf("%s", string);
    strreplace(string, "test", "foo");
    print(string);
    return 1;
}



Re: strreplace issue - [03]Garsino - 29.11.2010

pawn Код:
stock strreplace2(string[], const find[], const replace[], bool:ignorecase=false, count=cellmax, maxlength=sizeof(string))
{
    if(isnull(find) || isnull(string)) return 0;
    new matches;
    for(new idx, flen = strlen(find), rlen = strlen(replace), pos = strfind(string, find, ignorecase); pos != -1 && idx < maxlength && matches < count; pos = strfind(string, find, ignorecase, idx)) {
        strdel(string, pos, pos + flen);
        if(rlen) strins(string, replace, pos, maxlength);   // Crashy
        idx = pos + rlen;
        matches++;
    }
    return matches;
}
pawn Код:
public OnFilterScriptInit()
{
    new string[128];
    format(string, sizeof(string), "This is only a test, so don't ask!");
    print(string);
    strreplace2(string, "test", "foo");
    print(string);
    return 1;
}