You probably want to use the return value of nextToken
:
StringTokenizer numberOfPost_string = new StringTokenizer( numberOfPost_text , delimiters );
int numberOfPost = Integer.parseInt(numberOfPost_string.nextToken());
You can also do it with split
: (although this is probably slightly less efficient)
int numberOfPost = Integer.parseInt(numberOfPost_text.split(delimiters)[0]);
Keep in mind that split
takes a regular expression String
, thus to specify multiple options for characters, you will need to surround them by []
. To specify ;
, ,
or :
:
String delimiters = "[;,:]";