Reputation: 10531
StringTokenizer tokenizer = new StringTokenizer(s, " ,.:;?![]'");
Is there a way to also retrieve the delimiter, in this case all thee punctuation marks?
For example, "This is a test, and is that a test too?"
I want the result of tokenization also includes the two tokens , and ?
Is that possible?
Upvotes: 2
Views: 2868
Reputation: 311163
StringTokenizer
has an overloaded constructor that takes a third boolean
argument. Setting it to true
will make the tokenzier return the delimiters too:
StringTokenizer tokenizer = new StringTokenizer(s, " ,.:;?![]'", true);
// Here ---------------------------------------------------------^
Upvotes: 3