mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2006
Posts: 53
O
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 ?

Joined: Aug 2004
Posts: 7,252
R
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.

Joined: Sep 2003
Posts: 4,230
D
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

Joined: Jul 2006
Posts: 53
O
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.


Link Copied to Clipboard