/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package textBox;

/**
 *
 * @author jyounishi
 */
public class StringTokenizerEx{
    String str;
    String delim;
    int index;
    
    public StringTokenizerEx(String str, String delim){
        this.str=str;
        this.delim=delim;
        index=0;
    }
    
    public boolean hasMoreTokens(){
        int newIndex=index;
        boolean more=false;
        newIndex=str.indexOf(delim, index);
        if(newIndex>=0) more=true;
        if(newIndex<0&&index<str.length()) more=true;
        if(newIndex<0&&index>=str.length()) more=false;
        return more;
    }
    
    public String nextToken(){
        String outputString="";
        int newIndex=index;
        newIndex=str.indexOf(delim, index);
        //System.out.print("index="+index+" newIndex="+newIndex);
        if(newIndex>=0) {
            if(newIndex==index) {
                index+=delim.length();
                outputString=delim;
            }
            if(newIndex>index) {
                outputString=str.substring(index,newIndex)+delim;
                index=newIndex+delim.length();
            }
        }
        if(newIndex<0&&index<=str.length()) {
            outputString=str.substring(index,str.length());
            index+=str.length();
        }
        //System.out.println(" return index="+index);
        return outputString;
    }
}