jregex
Class RETokenizer
java.lang.Object
jregex.RETokenizer
- All Implemented Interfaces:
- java.util.Enumeration
public class RETokenizer
- extends java.lang.Object
- implements java.util.Enumeration
The Tokenizer class suggests a methods to break a text into tokens using
occurences of a pattern as delimiters.
There are two ways to obtain a text tokenizer for some pattern:
Pattern p=new Pattern("\\s+"); //any number of space characters
String text="blah blah blah";
//by factory method
RETokenizer tok1=p.tokenizer(text);
//or by constructor
RETokenizer tok2=new RETokenizer(p,text);
Now the one way is to use the tokenizer as a token enumeration/iterator:
while(tok1.hasMore()) System.out.println(tok1.nextToken());
and another way is to split it into a String array:
String[] arr=tok2.split();
for(int i=0;i
- See Also:
Pattern.tokenizer(java.lang.String)
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
RETokenizer
public RETokenizer(Pattern pattern,
java.lang.String text)
RETokenizer
public RETokenizer(Pattern pattern,
char[] chars,
int off,
int len)
RETokenizer
public RETokenizer(Pattern pattern,
java.io.Reader r,
int len)
throws java.io.IOException
- Throws:
java.io.IOException
RETokenizer
public RETokenizer(Matcher m,
boolean emptyEnabled)
setEmptyEnabled
public void setEmptyEnabled(boolean b)
isEmptyEnabled
public boolean isEmptyEnabled()
hasMore
public boolean hasMore()
nextToken
public java.lang.String nextToken()
split
public java.lang.String[] split()
reset
public void reset()
hasMoreElements
public boolean hasMoreElements()
- Specified by:
hasMoreElements
in interface java.util.Enumeration
nextElement
public java.lang.Object nextElement()
- Specified by:
nextElement
in interface java.util.Enumeration
- Returns:
- a next token as a String
Copyright © 2002-2007 JRuby Team. All Rights Reserved.