Mscape Help


How to use the Word List

The Word List tool allows you to check whether a particular word is present in an external file which contains a list of words split onto separate lines.

The text file

Obviously to use this tool the first thing you will need is a text file containing a list of words. Each new line in this file will be treated as a separate word so might look something like this:

fee
fi
fo
fum

Each line need not contain a single word: it could contain a pair of words separated by a space or a complete sentence; however the text you test against this will have to match exactly in order for it to be found by the Word List tool. Note that this means a word in your list that includes a trailing space would not be found if you searched for the word without the space: i.e. "fee" is not the same as "fee ".

To import the wordlist into the mediascape toolkit it will need to have a .txt extension.

Using the word list

Right click on Tools and select 'Import Word List File(s)'. Note that multiple files can be imported at once:

wordlist-1.gif

When you want to query a word list in your mediascape you must first load it using the Load action:

MyWordList.Load();

You might choose to do this when your mediascape first loads or at a given event. Until this load action is carried out all searches will fail and the length of the list will be zero. Once loaded you can check the length of the list with the 'ListLength' property. To test if a word is present in the list use the WordExists action in a condition:

if (MyWordList.WordExists("fee")) {
  // do this if the word is in the list
}
else {
  // otherwise do this
}

This will check if the word "fee" (without "inverted commas") exists in the loaded text file. Note that searches are case sensitive and, as mentioned above, trailing spaces could cause the search to fail.

Loading new lists

It is possible to work with a single Word List object and use this to test against multiple files by changing the 'Datafile' property and reloading the file. This might be preferable to using multiple Word List objects if your text files are large and could therefore impact on memory usage. As an example let's say you have two text files you need to check for the presence of the word "slug". You could check against both files using a single Word List object as follows:

MyTrueFalseVariable.Value = false;
MyWordList.Datafile = "TextFile1.txt";
MyWordList.Load();
if (MyWordList.WordExists("slug")) {
  MyTrueFalseVariable.Value = true;
}
MyWordList.Datafile = "TextFile2.txt";
MyWordList.Load();
if (MyWordList.WordExists("slug")) {
  MyTrueFalseVariable.Value = true;
}

If the word "slug" is found in either 'TextFile1.txt' or 'TextFile2.txt' 'MyTrueFalseVariable' will be set to true (this was used as an example, alternatively an event could be triggered). Note that the second 'Load()' is essential for this to work, otherwise the second search would still be carried out on 'TextFile1.txt'.

This approach could be extended further by using a loop to check for the presence of a word in a large number of text files (i.e. using an array of file names). Also, with a properly formed search term, it might even be possible to check against the contents of a log file...

Note that when assigning the file name using the 'Datafile' property you are able to load text files with extensions other than '.txt'.

Ready to
get started?

Download Mscape Suite Version 2.6 | 11 MB

Download Mscape Experimental

Experimental Beta Version 2.6 | 11 MB

Ask the Mscape Community

Forums