SA-MP Forums Archive
File - string search help - 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: File - string search help (/showthread.php?tid=88586)



File - string search help - GTA_Rules - 27.07.2009

Hey,

Since I'm not very good with files, coulnd't find anything on the wiki and didn't find anything on the forums either, I thought I'd just post here.
Anyways, I got this file called 'BanLog.txt' and 'KickLog.txt'. I want to make an IRC command like !whyban [playername] that shows all the times the player has been banned and/or kicked and what the reason was.

Stuff I can't figure out how to do:
Код:
[2009/7/23]-[8:30:12]: Matthias has been kicked by Matthias. [Reason: hai]
That is what a line in KickLog.txt looks like. I would like to check for the first 'Matthias' then show the admin who kicked him (second Matthias) and the reason.
I'm not asking for any code here, but I'd appreciate if you guys could give me an example of string-searching like that.

Thanks,
Matthias


Re: File - string search help - MadeMan - 27.07.2009

pawn Код:
new File:myhandle = fopen("KickLog.txt", io_read);
new line[256];
while(fread(myhandle, line))
{
    if(strfind(line, "Matthias") != -1)
    {
        //Then you have the right line's text saved to "line" string
    }
}
fclose(myhandle);



Re: File - string search help - GTA_Rules - 27.07.2009

Thanks, would that show every line? How do I get the admin name and reason? Sorry for all the questions


Re: File - string search help - MadeMan - 27.07.2009

Yes, it shows all the lines that have "Matthias" in it. I'm not sure how you find the info from that line. Maybe just show that line is enough?


Re: File - string search help - GTA_Rules - 27.07.2009

True thanks for your help.

Also: would ircSay(BotSwitcher(), blabla, line); work and show all lines?
How do I check how many lines were found?


Re: File - string search help - MadeMan - 27.07.2009

pawn Код:
new File:myhandle = fopen("KickLog.txt", io_read);
new line[256], linecount;
while(fread(myhandle, line))
{
    if(strfind(line, "Matthias") != -1)
    {
        linecount++;
    }
}
fclose(myhandle);



Re: File - string search help - GTA_Rules - 27.07.2009

Just thought of that, but thanks!