SA-MP Forums Archive
strfind wont work. - 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)
+--- Thread: strfind wont work. (/showthread.php?tid=530612)



strfind wont work. - Equality - 08.08.2014

hey. i just worte string into file and i tryed to look for some string in the file with strfind.
and it dosent found that.
pb:
http://pastebin.com/RQ697SMN
it fails to find "2" in the string. but its find 1. help?


Re: strfind wont work. - Equality - 08.08.2014

help?


Re: strfind wont work. - Jefff - 08.08.2014

fread(fh, str); reads only 1\r\n - one line

pawn Код:
new File:fh = fopen("text.txt",io_read);
    new line;
    while(fread(fh, str))
    {
        ++line;
        if(strfind(str,"2",true) != -1)
        {
            printf("succeed at line %d",line);
            break; // stops the loop
        }
        else print("failed");
    }
    fclose(fh);



Re: strfind wont work. - Equality - 08.08.2014

Quote:
Originally Posted by Jefff
Посмотреть сообщение
fread(fh, str); reads only 1\r\n - one line

pawn Код:
new File:fh = fopen("text.txt",io_read);
    new line;
    while(fread(fh, str))
    {
        ++line;
        if(strfind(str,"2",true) != -1)
        {
            printf("succeed at line %d",line);
            break; // stops the loop
        }
        else print("failed");
    }
    fclose(fh);
wow thanks.
but i want to break the loop, and also return 1;
how may i do that?


Re: strfind wont work. - Equality - 08.08.2014

look i have few strings, and it still dosent find them.
those strings:
ARTPEPEPEPE
ARTTTTTTTT
ARPEERERERR

i want it to recognize the second.
but it wont.
help?


Re: strfind wont work. - Jefff - 08.08.2014

pawn Код:
new File:fh = fopen("text.txt",io_read);
new Found;
while(fread(fh, str))
    if(strfind(str,"2",true) != -1)
    {
        Found = 1;
        break; // stops the loop
    }

fclose(fh);
return Found; // returns 0 if not found or 1 if match



Re: strfind wont work. - Equality - 08.08.2014

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
new File:fh = fopen("text.txt",io_read);
new Found;
while(fread(fh, str))
    if(strfind(str,"2",true) != -1)
    {
        Found = 1;
        break; // stops the loop
    }

fclose(fh);
return Found; // returns 0 if not found or 1 if match
thanks alot!