Java String Split splitStruct(String struct)

Here you can find the source of splitStruct(String struct)

Description

split Struct

License

Open Source License

Declaration

public static Vector splitStruct(String struct) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    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);// w  w  w .j a  va  2s .com
                    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();
    }
}

Related

  1. splitString(String string, int limit)
  2. splitStringBySeperator(final String str, final String seperator)
  3. splitStrings(String start, String end, int numSplitStrings, boolean oddLevel, List splits)
  4. splitStringToList(String pstrString, String pstrSep)
  5. splitStringWithoutTrim(String strInput, String strSplitor)
  6. splitSubstring(String str, String substr)
  7. splitTags(final String tagsString)
  8. splitTags(String rawTags)
  9. splitTemplateName(String templateName)