Using multiple delimiters with StringTokenizer

那年仲夏 提交于 2020-01-01 08:03:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!