From 667f6fcba58bbadbe085052d6fad28728c0e17f6 Mon Sep 17 00:00:00 2001 From: SowinskiBraeden Date: Fri, 21 Mar 2025 11:24:06 -0700 Subject: [PATCH] update bible word counter --- src/ca/bcit/comp1510/assignment2/q2/WordCounter.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ca/bcit/comp1510/assignment2/q2/WordCounter.java b/src/ca/bcit/comp1510/assignment2/q2/WordCounter.java index b16eda3..bd6c3b4 100644 --- a/src/ca/bcit/comp1510/assignment2/q2/WordCounter.java +++ b/src/ca/bcit/comp1510/assignment2/q2/WordCounter.java @@ -37,7 +37,9 @@ public class WordCounter { lineScan.useDelimiter(" "); while (lineScan.hasNext()) { - String word = lineScan.next().toLowerCase(); + String word = lineScan.next(). + toLowerCase(). + replaceAll("[^a-z]", ""); boolean exists = false; for (int i = 0; i < words.size() && !exists; i++) { @@ -47,8 +49,8 @@ public class WordCounter { exists = true; } } - - if (!exists && Pattern.matches("^[a-zA-Z]+", word)) { + + if (!exists && Pattern.matches("^[a-z]+", word)) { words.add(new Word(word)); } }