LemonMan
LemonMan

Reputation: 3153

Split on multiple characters

I'm doing this to split a string on pipes.

wordarray = comments.split("\\|");

I want that string to be split on both pipes and colons :

Is there a way I can combine those into command? Something like:

wordarray = comments.split("\\|",":")

Note, i want it to split on all the occurences not just the first one

Upvotes: 2

Views: 97

Answers (1)

anubhava
anubhava

Reputation: 786289

You can use character class for this. Consider this code:

String[] wordarray = comments.split("[|:]");

Upvotes: 6

Related Questions