xxxxxxxxxx
46
//parseDemo
//read from the file "do_we_not.txt", must be located in current sketch folder
//loadStrings returns an array of Strings which is stored in lines[]
//lines.length is equal to the number of newline characters found - 1
//Exercise: use the console to illustrate the step-by-step flow of this program
var lines = [];
function preload() {
//read and split by lines
lines = loadStrings("do_we_not.txt")
}
function setup() {
noCanvas()
console.log(lines)
var myText = "";
for (var i = 0; i < lines.length; i++) {
myText = myText + lines[i] + " "; // myText += lines[i];
}
console.log(myText)
//var questions = myText.split("?");
var tokens = myText.split(' '); // array of strings (token),split by whitespace (tokenizing)
console.log(tokens)
for (var t = 0; t < tokens.length; t++) {
var word = tokens[t]
console.log(t + "-> " + word);
for (var c = 0; c < tokens[t].length; c++) {
//console.log(tokens[t][c]);
console.log(word[c]);
//console.log(word.charAt(1));
}
}
//for each token (word,number,punctuation,etc)
//print token, preceded by token #
//for each char in token
//print char, preceeded by token index
//end inner for loop
//end outer for loop
}