Java tutorial
//package com.java2s; import java.io.BufferedReader; import java.io.StringReader; import java.util.ArrayList; public class Main { /** * get multiple lines from a string with \n * * @param strText the script to divide into single lines * @param strEndInstruction the character that marks the end of an instruction * @return */ public static ArrayList<String> getScriptLines(String strText, String strEndInstruction) throws Exception { // inits the list and the reader ArrayList<String> alLines = new ArrayList<String>(); BufferedReader br = new BufferedReader(new StringReader(strText)); String strLine = null; StringBuffer sbLine = new StringBuffer(); // reads the script through the reader while ((strLine = br.readLine()) != null) { // if is a comment skips the line if (strLine.length() == 0 || strLine.startsWith("\n") || strLine.startsWith("--") || strLine.startsWith("#")) continue; // adds the script line to the buffer sbLine.append(strLine); // if it's the end of the command, adds it to the AL if (strLine.trim().endsWith(strEndInstruction) || strEndInstruction.equals("")) { alLines.add(sbLine.toString()); sbLine = new StringBuffer(""); } } // and return the AL return alLines; } }