nikhil
nikhil

Reputation: 9385

Using multiple delimiters with StringTokenizer

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.

Upvotes: 15

Views: 37053

Answers (2)

JProgrammer
JProgrammer

Reputation: 1135

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.

Upvotes: 4

MByD
MByD

Reputation: 137322

Use the constructor with two arguments, where the second is the delimiters.

StringTokenizer tokenizer = new StringTokenizer(yourString, "!*^/");

Upvotes: 30

Related Questions