Big Bug Ban

兴趣 践行 创新

j2me StringTokenizer[存档]

 

/**
 * Copyright (c) 2010 princehaku
 * All right reserved.
 * Author princehaku
 * Site http://haku.hk
 * Created on : 2010-8-12, 21:54:50
 */

package net._3haku.util;

/**用于J2ME的分裂字符串函数
 *
 * @author princehaku
 */
public class StringTokenizer {
    /**源数据
     *
     */
    private String source;
    /**分离符
     *
     */
    private String sperator;
    /**当前解析到的位置
     *
     */
    private int pos;
    /**
     *
     * @param string
     * @param sperator
     */
    public StringTokenizer(String string, String sperator) {
        setSource(string);
        setSperator(sperator);
        pos=0;
    }
    /**是否还有分段
     * @return
     */
    public boolean hasMoreTokens() {
        //int pos1=getSource().indexOf(sperator,this.pos);
        if(pos>=getSource().length())
            return false;
        else
            return true;
    }
    /**下一个分段
     *
     * @return
     */
    public String nextToken() {
        int pos1=getSource().indexOf(sperator,this.pos);
        //如果找不到了..则将指针指向元素最大空间
        if(pos1==-1)
            pos1=getSource().length();
        int poslast=this.pos;
        this.pos=pos1+sperator.length();
        return getSource().substring(poslast, pos1);
    }
    private String getSource() {
        return source;
    }

    private void setSource(String source) {
        this.source = source;
    }
    
    private String getSperator() {
        return sperator;
    }

    private void setSperator(String sperator) {
        this.sperator = sperator;
    }


}

Written by princehaku

8月 15th, 2010 at 12:21 上午

Posted in java

Tagged with ,

with 2 comments

2 Responses to 'j2me StringTokenizer[存档]'

Subscribe to comments with RSS or TrackBack to 'j2me StringTokenizer[存档]'.

  1. 完全看不懂啊,只会一点点VB的人路过- –

    kingjue2

    1 9月 10 at 2:20 下午

  2. ^_^…我最开始也是学vb的…

    princehaku

    1 9月 10 at 4:07 下午

Leave a Reply