xxxxxxxxxx
50
var lines = [];
function preload() {
lines = loadStrings("do_we_not.txt")
}
function setup() {
noCanvas()
console.log(lines)
var myText = "";
var cTotal = 0;
for (var i = 0; i < lines.length; i++) {
cTotal = cTotal + lines[i].length
myText = myText +" "+ lines[i]; // myText += lines[i];
}
myText = myText.trim();
console.log(myText)
var tokens = myText.split(' '); // array of strings (token),split by whitespace (tokenizing)
console.log(tokens)
var cTotalNoWhite = 0;
var cTotalNoWhitePunc = 0;
for (var t = 0; t < tokens.length; t++) {
var word = tokens[t]
console.log(t + "-> " + word);
cTotalNoWhite = cTotalNoWhite + word.length;
for (var c = 0; c < tokens[t].length; c++) {
var cCode = word.getCharCodeAt(c)
if ((cCode < 48 && cCode > 57) && (cCode < 65 && cCode > 90) (cCode < 97 && cCode > 122) ) {
cTotalNoWhitePunc--;
}
}
}
cTotalNoWhitePunc = cTotalNoWhitePunc + cTotalNoWhite;
// results
console.log("line count ->" + lines.length); // mind the space in merging for loop
console.log("word count ->" + tokens.length); // use trim to get the right answer
console.log("character count ->" + cTotal);
console.log("character count no whitespace ->" + cTotalNoWhite);
console.log("character count no punctuation ->" + cTotalNoWhitePunc);
}