Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to scan for words in Java excluding punctuation
- Scanner fileScan= new Scanner(file);
- String word;
- while(fileScan.hasNext("[^ ,!?.]+")){
- word= fileScan.next();
- this.addToIndex(word, filename);
- }
- class S {
- public static void main(String[] args) {
- Scanner fileScan= new Scanner("hi my name is mario!").useDelimiter("[ ,!?.]+");
- String word;
- while(fileScan.hasNext()){
- word= fileScan.next();
- System.out.println(word);
- }
- } // end of main()
- }
- javac -g S.java && java S
- hi
- my
- name
- is
- mario
- word = word.replaceAll("\{Punct}", "");
Add Comment
Please, Sign In to add comment