strreplace isn't working for me
#1

strreplace won't replace it...anyone see anything wrong?
pawn Код:
if(dialogid == HOUSEMENU+14)
    {
        if(response)
        {
            if(strfind(inputtext, "%", CASE_SENSETIVE) != -1 || strfind(inputtext, "~", CASE_SENSETIVE) != -1) return ShowInfoBoxEx(playerid, COLOUR_SYSTEM, E_INVALID_HNAME_CHARS);
            if(strlen(inputtext) < MIN_HOUSE_NAME || strlen(inputtext) > MAX_HOUSE_NAME) return ShowInfoBoxEx(playerid, COLOUR_SYSTEM, E_INVALID_HNAME_LENGTH);
            else
            {
                strreplace("admin","dick",inputtext);
                format(hInfo[h][HouseName], MAX_HOUSE_NAME, "%s", inputtext);
                file = INI_Open(filename);
                INI_WriteString(file, "HouseName", inputtext);
                INI_Close(file);
                ShowInfoBox(playerid, I_HNAME_CHANGED, inputtext);
                UpdateHouseText(h);
            }
        }
        return 1;
    }
this will make it so when people try to put in their house name "admin" it will replace it with "dick"
Reply
#2

Pretty sure the parameters were in wrong positions (one of them).

Try this

pawn Код:
strreplace(inputtext, "admin","dick");
Reply
#3

nope, that didn't work ether.
Reply
#4

Try something like this:

pawn Код:
if(strfind(inputtext == "Admin"))
{
      strreplace(inputtext, "Dick");
      return 1;
}
Funny idea btw :P
Reply
#5

Post the strreplace function you're using
Reply
#6

Quote:
Originally Posted by judothijs
Посмотреть сообщение
Try something like this:

pawn Код:
if(strfind(inputtext == "Admin"))
{
      strreplace(inputtext, "Dick");
      return 1;
}
Funny idea btw :P
thanks, I did something similar:

pawn Код:
if(strfind(inputtext,"admin",true)!=-1)
{
    new adpoz = strfind(inputtext,"admin",true);
    strdel(inputtext,adpoz,adpoz+5);
    strins(inputtext,"dick",adpoz,strlen(inputtext));
}
@VincentDunn
I used dracoblue's utiles
pawn Код:
stock ret_memcpy(source[],index=0,numbytes)
{
    new tmp[200];
    new i=0;
    tmp[0]=0;
    if (index>=strlen(source)) return tmp;
    if (numbytes+index>=strlen(source)) numbytes=strlen(source)-index;
    if (numbytes<=0) return tmp;
    for (i=index;i<numbytes+index;i++) {
        tmp[i-index]=source[i];
        if (source[i]==0) return tmp;
    }
    tmp[numbytes]=0;
    return tmp;
}
stock strreplace(trg[],newstr[],src[])
{
    new f=0;
    new s1[128];
    new tmp[128];
    format(s1,sizeof(s1),"%s",src);
    f = strfind(s1,trg,true);
    tmp[0]=0;
    while (f>=0) {
        strcat(tmp,ret_memcpy(s1, 0, f));
        strcat(tmp,newstr);
        format(s1,sizeof(s1),"%s",ret_memcpy(s1, f+strlen(trg), strlen(s1)-f));
        f = strfind(s1,trg);
    }
    strcat(tmp,s1);
    return tmp;
}
but it would still be useful to know why strreplace didn't work
Reply
#7

http://forum.sa-mp.com/showpost.php?...postcount=3226
Reply
#8

thanks Vince.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)