public class StringMBTokenizer
extends java.lang.Object
implements java.util.Enumeration
--------------------------------------------------------------------------------
The String Multi-Byte Tokenizer allows an application to break a String into tokens. The tokenization method is such that the provided delimiter string, typically a string of 2 or more characters, is used as a single multi-byte delimiter. This differs from the java.util.StringTokenizer which uses each separate character in the delimiter string as a possible token delimiter.
The StringMBTokenizer methods do not distinguish among identifiers, numbers, and quoted strings, nor do they recognize and skip comments. Both the String to tokenize and the delimiter String are treated simply as literal text strings.
The multi-byte delimiter (the String that separates tokens) may be specified either at creation time, or on a per-token basis.
StringMBTokenizer will only return tokens. You cannot optionally request to also return delimiters. There is little need for that feature since there is only one active multi-byte delimiter at any given time.
A token is returned by taking a substring of the string that was used to create the StringMBTokenizer object.
Two multi-byte delimiters back-to-back delimit an inner empty string token.
A leading multi-byte delimiter delimits a leading empty string token.
A trailing multi-byte delimiter only terminates the preceding token. There is no
trailing empty string token following a trailing delimiter.
The following is one example of the use of the tokenizer. The code:
StringMBTokenizer st = new StringMBTokenizer("File->Menu->Menuitem","->");
while (st.hasMoreTokens()) {
println(st.nextToken());
}
prints the following output:
File
Menu
Menuitem
Constructor and Description |
---|
StringMBTokenizer(java.lang.String source,
java.lang.String delimiter)
Purpose: Constructs a string tokenizer for the specified string. |
Modifier and Type | Method and Description |
---|---|
int |
countTokens()
Purpose: Calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception. |
int |
countTokens(java.lang.String delimiter)
Purpose: Calculates the number of times that this tokenizer's nextToken(delimiter) method can be called before it generates an exception. |
boolean |
hasMoreElements()
Purpose: Returns the same value as the hasMoreTokens method. |
boolean |
hasMoreTokens()
Purpose: Tests if there are more tokens available from this tokenizer's string. |
static void |
main(java.lang.String[] args) |
java.lang.Object |
nextElement()
Purpose: Returns the same value as the nextToken method, except that its declared return value is Object rather than String. |
java.lang.String |
nextToken()
Purpose: Returns the next token from this string tokenizer. |
java.lang.String |
nextToken(java.lang.String delimiter)
Purpose: Returns the next token in this string tokenizer's string. |
public StringMBTokenizer(java.lang.String source, java.lang.String delimiter)
source
- string to be parseddelimiter
- string separating tokenspublic int countTokens()
public int countTokens(java.lang.String delimiter)
delimiter,
- String alternate delimiterpublic boolean hasMoreElements()
hasMoreElements
in interface java.util.Enumeration
public java.lang.Object nextElement() throws java.util.NoSuchElementException
nextElement
in interface java.util.Enumeration
java.util.NoSuchElementException
- - if there are no more tokens in this tokenizer's string.public boolean hasMoreTokens()
public java.lang.String nextToken() throws java.util.NoSuchElementException
java.util.NoSuchElementException
- - if there are no more tokens in this tokenizer's string.public java.lang.String nextToken(java.lang.String delimiter) throws java.util.NoSuchElementException
delimiter,
- String alternate delimiterjava.util.NoSuchElementException
- - if there are no more tokens in this tokenizer's string.public static void main(java.lang.String[] args)
Copyright © SAS Institute. All Rights Reserved.