For example, i have a file contains one sentence: That send, "a team to" the Super Bowl! saw on average an 18 percent increase. I want to only get words from this file(do not want symbols, " " ! .)
My codes:
File file = new File("1.txt");
try {
Scanner s = new Scanner(file);
while(s.hasNext())
{
String str = s.next();
if(str.contains(".")){
System.out.println("has ,");
}
System.out.println(str);
}
s.close();
However, this code will give me words with symbols following them. For example, it will return "a, instead of just a.
Aucun commentaire:
Enregistrer un commentaire