Here you can find the source of getStructValue(String struct, int index)
public static String getStructValue(String struct, int index)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static String getStructValue(String struct, int index) { Vector vr = splitStruct(struct); String value = (String) vr.elementAt(index); /*/*from w ww . j a v a2 s .co m*/ if (value.startsWith("[")) { int i=index+1; StringBuffer sb=new StringBuffer(value); while (!value.endsWith("]")) { value=(String)vr.elementAt(i); if (value.startsWith("[")) { value="]"; continue; } // end of if () sb.append(' '); sb.append(value); i++; } // end of while () value=sb.toString(); } // end of if () */ value = replace(value, "[", ""); value = replace(value, "]", ""); return value; } public static Vector splitStruct(String struct) { Vector vr = new Vector(); if (struct.startsWith("[") && struct.endsWith("]")) { struct = struct.substring(1, struct.length() - 1); } // end of if () StringTokenizer stok = new StringTokenizer(struct, " "); while (stok.hasMoreTokens()) { String tok = stok.nextToken(); if (tok.startsWith("[")) { StringBuffer sb = new StringBuffer(); while (!tok.endsWith("]")) { sb.append(tok); sb.append(' '); tok = stok.nextToken(); } // end of while () sb.append(replace(tok, "]", ""));//add last element tok = sb.toString(); } // end of if () vr.addElement(tok); } // end of while () return vr; } public static String replace(String body, String findString, String replaceString) { return replace(body, findString, replaceString, false); } public static String replace(String body, String findString, String replaceString, boolean once) { //StringBuffer newBodyBuffer = new StringBuffer (findString.length()*2); StringBuffer newBodyBuffer = new StringBuffer(); char[] chars = body.toCharArray(); int start = 0; while (true) { int index = body.indexOf(findString, start); if (index == -1) break; newBodyBuffer.append(chars, start, index - start); newBodyBuffer.append(replaceString); start = index + findString.length(); if (once) break; } newBodyBuffer.append(chars, start, chars.length - start); return newBodyBuffer.toString(); } }