Packagecom.ext.collections
Classpublic class StringTokenizer
InheritanceStringTokenizer Inheritance Object
Implements IIterator, IEnumeration

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

View the examples

See also

com.ext.collections.IIterator
com.ext.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, delimiters: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):IIterator
[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, delimiters: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 — the source String from which the tokens are to be extracted
 
delimiters:String — the 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):IIterator

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
IIterator — 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
flash.errors:IllegalOperationError
reset()method 
public function reset():void

Resets the position of the StringTokenizer to zero

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