I was wondering if there is any way in Java to tokenize an string by spaces, BUT if there are some words between apostrophes, take it as “one word”…
so for example, if I have:
This "is a great" day
the string tokenizer should have:
"This""is a great""day"
Thanks!
Using
String.split()and a regex, not aStringTokenizer, how about:Output:
From your example, I assume you mean double-quotes (“) not apostrophes (‘).
NB: I initially posted something much simpler, which worked for your example, but not for input like: