Tuesday, February 5, 2019

Java string.split - by multiple character delimiter?

String.split takes a regular expression, in this case, you want non-word characters (regex \W) to be the split, so it's simply:
String input = "Hi,X How-how are:any you?";
String[] parts = input.split("[\\W]");

No comments:

Post a Comment