日期:2014-05-20 浏览次数:20790 次
/** * Split string into multiple strings * @param original Original string * @param separator Separator string in original string * @return Splitted string array */ private String[] split(String original, String separator) { Vector nodes = new Vector(); // Parse nodes into vector int index = original.indexOf(separator); while(index>=0) { nodes.addElement( original.substring(0, index) ); original = original.substring(index+separator.length()); index = original.indexOf(separator); } // Get the last node nodes.addElement( original ); // Create splitted string array String[] result = new String[ nodes.size() ]; if( nodes.size()>0 ) { for(int loop=0; loop<nodes.size(); loop++) result[loop] = (String)nodes.elementAt(loop); } return result; } /** * Split string into multiple strings * @param original Original string * @param separator Separator string in original string * @return Splitted string array */ private Vector split2Vector(String original, String separator) { Vector nodes = new Vector(); // Parse nodes into vector int index = original.indexOf(separator); while(index>=0) { nodes.addElement( original.substring(0, index) ); original = original.substring(index+separator.length()); index = original.indexOf(separator); } // Get the last node nodes.addElement( original ); return nodes; }?
/** * Split string into multiple strings * @param original Original string * @param separator Separator string in original string * @return Splitted string array */ private String[] split(String original, String separator) { Vector nodes = new Vector(); // Parse nodes into vector int index = original.indexOf(separator); while (index >= 0) { nodes.addElement(original.substring(0, index)); original = original.substring(index + separator.length()); index = original.indexOf(separator); } // Get the last node if(original.length()>0){ nodes.addElement(original); } // Create splitted string array String[] result = new String[nodes.size()]; if (nodes.size() > 0) { for (int loop = 0; loop < nodes.size(); loop++) { result[loop] = (String) nodes.elementAt(loop); } } return result; }