mIRC Home    About    Download    Register    News    Help

Print Thread
quick question about /write to a .txt file #157630 27/08/06 02:44 AM
Joined: Jul 2006
Posts: 53
O
oblivious Offline OP
Babel fish
OP Offline
Babel fish
O
Joined: Jul 2006
Posts: 53
I'm building a text file full of words, one word on every line of the file. This file will have hundreds of words that I will be adding, how do I make sure I don't add the same word to the same text file more than once ?

Re: quick question about /write to a .txt file #157631 27/08/06 02:50 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
You could do a search for each word, then if it's not found, add it.

I'm going to presume that this is going to be used in conjunction with an on text event. If this is the case, I'd like to point out that using a text file is the slowest way of storing information that needs to be accessed.

I'd highly recommend that you consider forgetting about the text file, and use a hash table instead. If you need assistance with creating/using a hash table, I'd be more than happy to assist.

Re: quick question about /write to a .txt file #157632 27/08/06 09:06 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
if (!$read(filename.txt,s,%word) && !$readn) { write filename.txt %word }

$read with the ,s switch searchs for line that begines with the word(s) in %word and returns the rest of the line minus them word(s) at the front this causes a line with only the word on it to actually bring back a $null reply (makes it look like it doesnt exist unfortunitly) BUT the solution is to check $readn which is the line number it was matched at, so if both no reply from $read and no $readn value then the line wasnt matched. So add it

Re: quick question about /write to a .txt file #157633 27/08/06 05:42 PM
Joined: Jul 2006
Posts: 53
O
oblivious Offline OP
Babel fish
OP Offline
Babel fish
O
Joined: Jul 2006
Posts: 53
I'll have to get back to you on the hash tables. For now I will deal with the text files , the code that DaveC has provided works perfectly. Thanks for helping.