⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stringparser.java

📁 《神州》RPG游戏引擎
💻 JAVA
字号:
import java.util.Vector;

public class StringParser
{
    private String reqStr;

    public StringParser()
    {
        reqStr="";
    }
    public StringParser(String str)
    {
        reqStr = str;
    }

    public void init(String str)
    {
        reqStr = str;
    }

    public String getValue(String key)
    {
        int beginIndex = reqStr.indexOf(key + "=");
        if (beginIndex == -1)
            return "";
        beginIndex = beginIndex + (key + "=").length();
        if (beginIndex >= reqStr.length())
        {
            return "";
        }
        int endIndex = reqStr.indexOf("&&", beginIndex);
        if (endIndex == -1)
            endIndex = reqStr.length();

        return reqStr.substring(beginIndex, endIndex);
    }

    public int getIntValue(String strValue)
    {
        int returnValue = 0;
        try
        {
            returnValue = Integer.parseInt(getValue(strValue));
        }
        catch(Exception ex)
        {
            //System.out.println(ex.getMessage());
            returnValue = 0;
        }
        return returnValue;
    }

    public String[] getValues(String key)
    {
        Vector vc = new Vector();
        int beginIndex = 0, endIndex = 0;

        while (true)
        {
            beginIndex = reqStr.indexOf(key + "=", endIndex);
            if (beginIndex == -1)
                break;
            beginIndex = beginIndex + (key + "=").length();
            if (beginIndex >= reqStr.length())
                break;

            endIndex = reqStr.indexOf("&&", beginIndex);
            if (endIndex == -1)
                endIndex = reqStr.length();
            vc.addElement(reqStr.substring(beginIndex, endIndex));
        }

        if (vc.size() > 0)
        {
            String[] returnArr = new String[vc.size()];
            for (int i = 0; i < returnArr.length; i++) {
                returnArr[i] = (String) vc.elementAt(i);
            }
            return returnArr;
        }
        else {
            return null;
        }

    }

    public int[] getIntValues(String key)
    {
        Vector vc = new Vector();
        int beginIndex = 0, endIndex = 0;

        while (true)
        {
            beginIndex = reqStr.indexOf(key + "=", endIndex);
            if (beginIndex == -1)
                break;
            beginIndex = beginIndex + (key + "=").length();
            if (beginIndex >= reqStr.length())
                break;
            endIndex = reqStr.indexOf("&&", beginIndex);
            if (endIndex == -1)
                endIndex = reqStr.length();
            vc.addElement(reqStr.substring(beginIndex, endIndex));
        }
        if (vc.size() > 0)
        {
            int[] returnArr = new int[vc.size()];

            for (int i = 0; i < returnArr.length; i++)
            {
                returnArr[i] = getIntValue( (String) vc.elementAt(i));
            }
            return returnArr;
        }
        else {
            return null;
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -