问题
I'd like to know how I can use multiple delimiters with StringTokenizer in java.
For example one of these !,*,/,^
will occur as a delimiter. Also there will only be one at a time.
回答1:
Use the constructor with two arguments, where the second is the delimiters.
StringTokenizer tokenizer = new StringTokenizer(yourString, "!*^/");
回答2:
You can use String.split() method because it takes regex as a parameter. You can specify Regex such that it can split the string based upon one of these deliminators.
来源:https://stackoverflow.com/questions/9446704/using-multiple-delimiters-with-stringtokenizer