Java String Split by Line split(String line, String regex)

Here you can find the source of split(String line, String regex)

Description

split

License

Open Source License

Declaration

public static String[] split(String line, String regex) 

Method Source Code

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

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static String[] split(String line, String regex) {
        List<String> strings = new ArrayList<String>();
        String part = "";
        for (int i = 0; i < line.length() - (regex.length() - 1); i++) {
            if (line.substring(i, i + regex.length()).equalsIgnoreCase(
                    regex)) {//from   w  w  w .j a va2s. c om
                strings.add(part);
                part = "";
                i = i + regex.length() - 1;
            } else {
                part += line.charAt(i);
            }
        }
        strings.add(part);
        String[] parts = new String[strings.size()];
        for (int i = 0; i < strings.size(); i++) {
            parts[i] = strings.get(i);
        }
        return parts;
    }
}

Related

  1. split(String line)
  2. split(String line)
  3. split(String line, char delimiter)
  4. split(String line, char delimiter)
  5. split(String line, String delimiter)
  6. split(String line, String separator)
  7. split(String line, String separator)
  8. split(String line, String separator)
  9. split(String line, String separator)