Skip to content

Instantly share code, notes, and snippets.

@slambert
Created April 26, 2017 14:58
Show Gist options
  • Save slambert/903ee2e26a4b1a390ddaa4ecd3079d19 to your computer and use it in GitHub Desktop.
Save slambert/903ee2e26a4b1a390ddaa4ecd3079d19 to your computer and use it in GitHub Desktop.
Tests a word against a list of words
/* Bad Word Checker
Tests a word against a list of words
Better put: tests a string against an array of strings
Steve Lambert April 26, 2017
*/
// VARIABLES
String filename = "wordlist.txt"; // file with words to check against
String[] lines; // array of the lines in the file
String testword = "you"; // word you are testing
void setup() {
size(250,250);
smooth();
// load the file into an array{
lines = loadStrings(filename);
// Launch info!
// how many lines are in that text file?
println("there are " + lines.length + " lines");
// show me what's in the text file
for (int i = 0 ; i < lines.length; i++) {
println(lines[i]);
}
// Launch confirmation
println("PROGRAM IS LAUNCHED!");
println("");
} // end setup, let's get started.
void draw() {
if (frameCount % 100 == 0){ // Every 100 frames...
for (int i = 0 ; i < lines.length; i++) {
if(lines[i].equals(testword)){
println("We have a match! " + lines[i] + " = " + testword);
} else {
println(lines[i] + " != " + testword);
} // end if
} // end for
println("");
} // end modulo if
} // end draw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment