xxxxxxxxxx
59
let rawText;
let joinedText;
let words;
let searchword ="Dracula";
let inputtext;
let button;
let count = 0;
function preload(){
rawText = loadStrings("dracula.txt");
}
function setup() {
inputtext = createInput(searchword);
button = createButton("Submit Search");
button.mousePressed(searchNewWord);
createCanvas(800, 400);
//console.log(rawText);
joinedText = join(rawText," ");
console.log(joinedText);
words = splitTokens(joinedText,' ');
// console.log(words);
for(let i= 0 ; i< words.length ;i++){
if(words[i] == searchword){
count++;
console.log("i got a match for the word: "+ searchword);
}
}
textSize(36);
}
function searchNewWord(){
searchword =inputtext.value();
// console.log(typeof(searchword))
// count = 0
for(let i= 0 ; i< words.length ;i++){
if(words[i] == searchword){
count++;
console.log("i got a match for the word: "+ searchword);
}
}
// let results = match(joinedText, searchword+'*')
// console.log(results)
}
function draw() {
background(220);
text("i got a match for the word: "+ searchword, 10,40);
text(searchword + " appears "+ count+ " times", 10, 80);
}