mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Sep 2003
Posts: 42
Demarko Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Sep 2003
Posts: 42
Hi guys,
I need some help coding a little "search a textfile for some info" script:

I have a plain text file that looks like the following:

Code:
[Entry13]
names=nom1 nom2 nom5 nom8
update=2011-05
sports=sp1 sp3 sp5 sp7 sp9

[Entry56]
names=nom1 nom2 nom3 nom4
update=2011-07
sports=sp1 sp2 sp3 sp4 sp5

[Entry9]
names=nom1 nom2 nom5 nom8
update=2011-07
sports=sp4 sp6 sp8 sp10


...and so on...
If I type "!names Entry13" it will return "nom1 nom2 nom5 nom8". That works and is not the problem.

But what Im missing is the option to search through all entries, for example:
typing "!names nom4" should return "nom4 belongs to Entry56"
while "!names nom8" should return "nom8 belongs to Entry13 Entry56"
also "!sports sp4" should return "sp4 is part of Entry56 Entry9"
and "!sports sp10" should return "sp10 is part of Entry9"

So it should go and check every EntryXX and return the ones that match as described above.
On the one hand that sounds quite simple, but on the other hand I'm not a programmer and therefor I have no real clue how to write the corresponding code for it.


So any help is highly appreciated.
Many Thanks in advance. smile

Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Code:
alias search_all {
var %file file.txt ,%a 1 ,%r ,%v
while ($ini(%file,%a)) {
%v = $v1
if ($istok($readini(%file,%v,$1),$2,32)) %r = %r %v 
inc %a
}
return %r
}
$search_all(names,nom8) return Entry13 Entry56 for example. Don't forget to replace %file with your filename


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Sep 2003
Posts: 42
Demarko Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Sep 2003
Posts: 42
Yeah, that does the job! grin

Thanks Wims


Link Copied to Clipboard