Java String Split by Char splitEncolosed(String s, char open_tag, char close_tag)

Here you can find the source of splitEncolosed(String s, char open_tag, char close_tag)

Description

split Encolosed

License

Open Source License

Declaration

public static ArrayList<String> splitEncolosed(String s, char open_tag, char close_tag) 

Method Source Code


//package com.java2s;
// it under the terms of the GNU General Public License as published by

import java.util.ArrayList;

public class Main {
    public static ArrayList<String> splitEncolosed(String s, char open_tag, char close_tag) {
        ArrayList<String> ret = new ArrayList<String>();
        char[] chars = s.toCharArray();
        String contents = "";
        for (char c : chars) {
            if (c == open_tag) {
                if (!contents.isEmpty()) {
                    ret.add(contents);/* w  w w .j  a v  a 2  s  . c o m*/
                }
                contents = "";
            } else if (c == close_tag) {
                ret.add(contents);
                contents = "";
            } else {
                contents += c;
            }
        }
        if (!contents.isEmpty()) {
            ret.add(contents);
            contents = "";
        }
        return ret;
    }
}

Related

  1. splitAt(String inputString, Character inputChar)
  2. splitAt(String str, char c)
  3. splitByChar(final String message, final char ch)
  4. splitByNonNestedChars(String s, char... c)
  5. splitChars(String input, String charsToBeRemoved)
  6. splitFast3(String data, char splitChar)
  7. splitInclusive(CharSequence input, char[] splitChars)
  8. splitList(String source, char useChar)
  9. splitOnChar(String str, char c)