Java Vector from String getKeyStringAsVector(String keyString, String separator)

Here you can find the source of getKeyStringAsVector(String keyString, String separator)

Description

Return a vector of strings with one element per key value NOTE: An empty string ("") will be regarded as a value, therefor is StringTokenizer not used.

License

Open Source License

Parameter

Parameter Description
keyString String with each key value separated by the separator
separator The sparator used in the key string

Return

Vector with one element per key

Declaration

public static Vector getKeyStringAsVector(String keyString,
        String separator) 

Method Source Code

//package com.java2s;
/* IBS Copyright/Security Notice ***************************************
 *                                              
 *  BAP Property of IBS AB//from  w w w  . jav a  2  s .  c om
 *  (C) Copyright IBS AB 2001-2003
 *  All rights reserved.                        
 *  Use, duplication, or disclosure restricted  
 *  by license agreement with IBS AB.           
 *                                              
 *  Licensed Materials - Property of IBS AB     
 *                                              
 * End IBS Copyright/Security Notice **********************************
 *
 *
 * User  Date          Comment     
 * ---------------------------------------------------------------------
 * DMA   01/01/2000    Class created
 *  
 ***********************************************************************/

import java.util.*;

public class Main {
    /**
     * Return a vector of strings with one element per key value
     * 
     * NOTE: An empty string ("") will be regarded as a value, therefor is 
     *       StringTokenizer not used.
     * 
     * Example:  ",A,,B," will result in Vector with 5 elements[ A B ] 
     *           For tokenizer would the result have been a Vector of 2 elements [AB]
     *
     * @param   keyString      String with each key value separated by the separator
     * @param   separator       The sparator used in the key string
     * @return  Vector with one element per key 
     */
    public static Vector getKeyStringAsVector(String keyString,
            String separator) {

        if (keyString == null) {
            return null;
        }

        Vector v = new Vector();
        int xb = 0;
        int xe = 0;
        boolean loop = true;
        while (loop) {
            xe = keyString.indexOf(separator, xb);
            if (xe < 0) {
                xe = keyString.length();
                loop = false;
            }
            v.add(keyString.substring(xb, xe));
            xb = xe + separator.length();
        }
        return v;
    }
}

Related

  1. constructFilter(String hostname, Vector schedulertypes)
  2. containSource(Vector sources, String source)
  3. convertStringToVector(String source, String separator)
  4. createNodeValueVector(final String val)
  5. getposString(Vector vect_valores, String valor)
  6. getStringFromTokens(Vector vector, String delimiter)
  7. implode(Vector handler, String separator)
  8. implode(Vector strings, char delim)