Packagecom.ericfeminella.collections
Classpublic class StringTokenizer
ImplementsIEnumeration, Iterator

StringTokenizer provides a simple API from which Strings can be split into individual tokens based on a specific delimiter.

StringTokenizer provides an Iterator and IEnumeration implementation, thus making it easy to implement as either interface.

Additionally, StringTokenizer provides two static factory methods for creating an instance as either implementaton These convenience factory methods are createIterator and createEnumeration


Example
     var tokens:StringTokenizer = StringTokenizer("hello world", " ");
     
     while ( tokens.hasMoreTokens() )
     {
         trace( tokens.nextToken() );
     }
     // outputs:
     // hello
     // world
          

See also

com.ericfeminella.collections.Iterator
com.ericfeminella.collections.IEnumeration


Protected Properties
 PropertyDefined by
  cursor : int
Stores the current position (cursor) in the tokens array from which calls to nextToken(); are based on
StringTokenizer
  delimiter : String
Defines the delimiter from which the source String tokens are to be extracted
StringTokenizer
  source : String
The source String from which tokens are extracted from based on the specified delimiter
StringTokenizer
  tokens : Array
Defines the token Array which contains each token String extracted by the StringTokenizer instance
StringTokenizer
Public Methods
 MethodDefined by
  
StringTokenizer(source:String, delimiter:String)
Creates a new instance of StringTokenizer and processes the source String into an array of tokens based on the specified delimiter
StringTokenizer
  
Retrieves the length of tokens extracted from the source String
StringTokenizer
  
createEnumeration(source:String, delimiter:String):IEnumeration
[static] Static Factory method which creates a new IEnumeration StringTokenizer implementation
StringTokenizer
  
createIterator(source:String, delimiter:String):Iterator
[static] Static Factory method which creates a new Iterator StringTokenizer implementation
StringTokenizer
  
hasMoreElements():Boolean
IEnumeration implementation which determines if there are more tokens which have yet to be retrieved via calls to nextToken
StringTokenizer
  
hasMoreTokens():Boolean
Determines if there are more tokens which have yet to be retrieved via calls to nextToken
StringTokenizer
  
hasNext():Boolean
Iterator implementation which determines if there are more tokens which have yet to be retrieved via calls to nextToken
StringTokenizer
  
next():*
Retrieves the next element in the StringTokenizer instance
StringTokenizer
  
Retrieves the next token in the StringTokenizer instance
StringTokenizer
  
nextToken():String
Retrieves the next token in the StringTokenizer instance.
StringTokenizer
  
position():int
Determines the current position within the token
StringTokenizer
  
remove():void
Remove must be implemented to provide a standard iterator implementation.
StringTokenizer
  
reset():void
Resets the position of the StringTokenizer to zero
StringTokenizer
Property detail
cursorproperty
protected var cursor:int

Stores the current position (cursor) in the tokens array from which calls to nextToken(); are based on

delimiterproperty 
protected var delimiter:String

Defines the delimiter from which the source String tokens are to be extracted

sourceproperty 
protected var source:String

The source String from which tokens are extracted from based on the specified delimiter

tokensproperty 
protected var tokens:Array

Defines the token Array which contains each token String extracted by the StringTokenizer instance

Constructor detail
StringTokenizer()constructor
public function StringTokenizer(source:String, delimiter:String)

Creates a new instance of StringTokenizer and processes the source String into an array of tokens based on the specified delimiter

Parameters
source:String — source String from which the tokens are to be extracted
 
delimiter:String — delimiter on which the tokens are extracted

Example
                  var tokens:StringTokenizer = new StringTokenizer("This is a test", " ");
                  trace( tokens.countTokens() );
                  

Method detail
countTokens()method
public function countTokens():int

Retrieves the length of tokens extracted from the source String

Returns
int — the length of tokens in the source
createEnumeration()method 
public static function createEnumeration(source:String, delimiter:String):IEnumeration

Static Factory method which creates a new IEnumeration StringTokenizer implementation

Parameters
source:String — the source String from which the tokens are to be extracted
 
delimiter:String — the delimiter on which the tokens are extracted

Returns
IEnumeration — a new StringTokenizer as an IEnumeration

Example
         var tokens:IEnumeration = StringTokenizer.createEnumeration("This is a test", " ");
         
         while ( tokens.hasMoreElements() )
         {
             trace( tokens.nextElement() );
         }
                  

createIterator()method 
public static function createIterator(source:String, delimiter:String):Iterator

Static Factory method which creates a new Iterator StringTokenizer implementation

Parameters
source:String — the source String from which the tokens are to be extracted
 
delimiter:String — the delimiter on which the tokens are extracted

Returns
Iterator — a new StringTokenizer as an Iterator

Example
         var tokens:Iterator = StringTokenizer.createIterator("This is a test", " ");
         
         while ( tokens.hasNext() )
         {
             trace( tokens.next() );
         }
                  

hasMoreElements()method 
public function hasMoreElements():Boolean

IEnumeration implementation which determines if there are more tokens which have yet to be retrieved via calls to nextToken

Returns
Boolean — true if more tokens remain, otherwise false
hasMoreTokens()method 
public function hasMoreTokens():Boolean

Determines if there are more tokens which have yet to be retrieved via calls to nextToken

Returns
Boolean — true if more tokens remain, otherwise false
hasNext()method 
public function hasNext():Boolean

Iterator implementation which determines if there are more tokens which have yet to be retrieved via calls to nextToken

Returns
Boolean — true if more tokens remain, otherwise false
next()method 
public function next():*

Retrieves the next element in the StringTokenizer instance

Returns
* — the next token based on the current position
nextElement()method 
public function nextElement():*

Retrieves the next token in the StringTokenizer instance

Returns
* — the next token in the source String
nextToken()method 
public function nextToken():String

Retrieves the next token in the StringTokenizer instance.

If the current position of the StringTokenizer instance is greater than or equal to the length of the source a null value is returned

Returns
String — the next token in the source String
position()method 
public function position():int

Determines the current position within the token

Returns
int — the current index of the token
remove()method 
public function remove():void

Remove must be implemented to provide a standard iterator implementation.

Typically this method would not provide an actual implementation as a concrete iterator is not to perform modifications, but rather simply provide a mechanism for iterating the object, thus being considered as read-only. Therefore concrete implementationx should throw an Exception


Throws
reset()method 
public function reset():void

Resets the position of the StringTokenizer to zero