File - string search help
#1

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:
  • Searching for the param used in the command in all of the lines of that file.
  • If the param was found in a line, take out all of the information I need and put it in a string.
Код:
[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
Reply
#2

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);
Reply
#3

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

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?
Reply
#5

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?
Reply
#6

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);
Reply
#7

Just thought of that, but thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)