Can Read TextFile and split it into individual words without , . ! ? ""
parent
af0e73393c
commit
c7a8d2f24c
|
|
@ -1,3 +1,6 @@
|
|||
void main() {
|
||||
|
||||
IO.println(
|
||||
TextReader.linesToWords(TextReader.readFile(
|
||||
"C:\\Users\\Toni G\\IdeaProjects\\GitPeerGroup\\src\\BeeMovieScript.txt")));
|
||||
}
|
||||
|
|
@ -5,7 +5,10 @@ import java.util.Scanner;
|
|||
import java.util.ArrayList;
|
||||
|
||||
public class TextReader {
|
||||
public ArrayList<String> readFile(String filePath) {
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
public static ArrayList<String> readFile(String filePath) {
|
||||
ArrayList<String> lines = new ArrayList<>();
|
||||
File file = new File (filePath);
|
||||
|
||||
|
|
@ -20,12 +23,24 @@ public class TextReader {
|
|||
return lines;
|
||||
}
|
||||
|
||||
public ArrayList<String> linesToWords(ArrayList<String> lines) {
|
||||
public static ArrayList<String> linesToWords(ArrayList<String> lines) {
|
||||
ArrayList<String> words = new ArrayList<>();
|
||||
for (String line : lines) {
|
||||
|
||||
String[] currentLine = line.split(" ");
|
||||
|
||||
for (String word : currentLine) {
|
||||
for (int i = 0; i < word.length(); i++) {
|
||||
word = word.replace(",", "")
|
||||
.replace(".", "")
|
||||
.replace("!", "")
|
||||
.replace("?", "")
|
||||
.replace("\"", "");
|
||||
|
||||
}
|
||||
words.add(word);
|
||||
}
|
||||
}
|
||||
return words;
|
||||
}
|
||||
|
||||
//end my suffering
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue