mIRC Homepage
Posted By: oblivious quick question about /write to a .txt file - 27/08/06 02:44 AM
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 ?
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.
Posted By: DaveC Re: quick question about /write to a .txt file - 27/08/06 09:06 AM
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
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.
© mIRC Discussion Forums