woopata
woopata

Reputation: 875

Explain delimiter for java tokenizer

Explain this:

"\t\n\r\">#"

it's used in Java tokenizer.

StringTokenizer st = new StringTokenizer(remaining, "\t\n\r\">#");

Upvotes: 0

Views: 9164

Answers (3)

Aitor Carrera
Aitor Carrera

Reputation: 351

This is not a regexp,this means

\t is tab \n is end of line \r is carriage return \" is " character ">" and "#" are the respective characters.

This string tokenizer will break the string "remaining" into tokens, separating the string in any of the previous characters.

Upvotes: 0

David Heffernan
David Heffernan

Reputation: 612954

That's a delimiter set for the tokenizer. It is not a regular expression as you originally suspected.

From the documentation of the StringTokenizer constructor:

The characters in the delim argument are the delimiters for separating tokens. Delimiter characters themselves will not be treated as tokens.

The documentation for the constructor overload that does not have the delim argument gives an idea of what type of string might be expected:

Constructs a string tokenizer for the specified string. The tokenizer uses the default delimiter set, which is " \t\n\r\f": the space character, the tab character, the newline character, the carriage-return character, and the form-feed character. Delimiter characters themselves will not be treated as tokens.

The code you have is specifying a different set of delimiters from the default.

Upvotes: 7

Colin Hebert
Colin Hebert

Reputation: 93167

As for the question itself, it's not a regular expression but a set of delimiter characters.


Resources :

Upvotes: 2

Related Questions