Guest User

Untitled

a guest
Aug 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. How to scan for words in Java excluding punctuation
  2. Scanner fileScan= new Scanner(file);
  3. String word;
  4. while(fileScan.hasNext("[^ ,!?.]+")){
  5. word= fileScan.next();
  6. this.addToIndex(word, filename);
  7. }
  8.  
  9. class S {
  10.  
  11. public static void main(String[] args) {
  12. Scanner fileScan= new Scanner("hi my name is mario!").useDelimiter("[ ,!?.]+");
  13. String word;
  14. while(fileScan.hasNext()){
  15. word= fileScan.next();
  16. System.out.println(word);
  17. }
  18.  
  19. } // end of main()
  20. }
  21.  
  22.  
  23. javac -g S.java && java S
  24. hi
  25. my
  26. name
  27. is
  28. mario
  29.  
  30. word = word.replaceAll("\{Punct}", "");
Add Comment
Please, Sign In to add comment