得到字符串的token

得到字符串的token
private static int nextToken(String url, int pos, StringBuffer token) {
        token.setLength(0);

        while (pos < url.length()) {
            char ch = url.charAt(pos++);

            if (ch == ':' || ch == ';') {
                break;
            }

            if (ch == '/') {
                if (pos < url.length() && url.charAt(pos) == '/') {
                    pos++;
                }

                break;
            }

            token.append(ch);
        }

        return pos;
    }

上面代码中token.setLength(0);的作用是每次都把字符串缓冲区清空,也就是重置的作用.
上面代码作用是每次得到指定的一段.例如"jdbc:jtds:sqlserver://hostname/dbname"
token为jdbc,jtds,sqlserver,hostname,dbname

你可能感兴趣的:(得到字符串的token)