public class Tokenizer extends Object
The Tokenizer divides a line into tokens separated by deliminators. There can be any number of deliminators set. All of the deliminators are treated equally.
There can be at most one quote character set. If it is set then deliminators inside of a quoted string are treated as part of the string and not as deliminators. The quotes are not returned as part of the token. To escape a quote, repeat it.
Constructor and Description |
---|
Tokenizer(String deliminators,
char quote,
boolean mergeMultipleDeliminators)
Creates a Tokenizer.
|
Modifier and Type | Method and Description |
---|---|
int |
countTokens()
Returns the number of times that the nextToken method
can be called without generating an exception.
|
boolean |
hasMoreTokens()
Returns true if a call to nextToken will not generate
an exception.
|
String |
nextToken()
Returns the next token.
|
void |
parse(String line)
Sets the line to be tokenized.
|
public Tokenizer(String deliminators, char quote, boolean mergeMultipleDeliminators)
deliminators
- is a String containing the deliminator characters.quote
- is a char containing the quote character.
If 0 then quoting is disabled.mergeMultipleDeliminators
- is true if multiple consecutive deliminators
are to be treated as a single deliminator.public void parse(String line)
line
- is the line to be tokenized.public boolean hasMoreTokens()
public int countTokens()
public String nextToken()
NoSuchElementException
- if there are no more tokens
to be returned.Copyright © 2020 Rogue Wave Software. All rights reserved.