From 2513999d29a854324154d641ef86454d081d8c7e Mon Sep 17 00:00:00 2001 From: eugenefischer Date: Fri, 3 Jul 2020 16:26:13 -0500 Subject: [PATCH] stripping out punctuation --- Sorting/RandomWordFileReader.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sorting/RandomWordFileReader.java b/Sorting/RandomWordFileReader.java index a04c02c..9c87ad1 100644 --- a/Sorting/RandomWordFileReader.java +++ b/Sorting/RandomWordFileReader.java @@ -14,10 +14,13 @@ public class RandomWordFileReader { public RandomWordFileReader(String filename){ try(BufferedReader reader = Files.newBufferedReader(Path.of(filename));){ //This should use flatMap to make a string array from the line, and then turn the elements of that array into a stream, which goes to forEach - reader.lines().flatMap(line -> Arrays.stream(line.split("\\s+"))).forEach(word -> words.add(word.toLowerCase())); + reader.lines().flatMap(line -> Arrays.stream(line.split("[\\s\\W_0]+"))).forEach(word -> words.add(word.toLowerCase())); }catch (IOException ex){ System.err.println(ex); } + /*for (String e : words) { + e = e.replaceAll("\\W+",""); + }*/ } public ArrayList getWords(){