Here you can find the source of removeNLinesForwardsFromStringMatch(String text, String match, int n)
public static String removeNLinesForwardsFromStringMatch(String text, String match, int n)
//package com.java2s; //License from project: Open Source License import java.util.Scanner; public class Main { /**/*from www . j a v a2 s . com*/ * Removes the first n lines within a plain text from the position * where the search string is located, inclusive. */ public static String removeNLinesForwardsFromStringMatch(String text, String match, int n) { Scanner scanner = new Scanner(text); String line = null, result = ""; while (scanner.hasNextLine()) { line = scanner.nextLine(); if (line.matches("(" + match + ").*")) { int i = 0; while (scanner.hasNextLine() && i < n) { scanner.nextLine(); i++; } } else result += line + "\n"; } scanner.close(); return result; } }