String (String string, int start, int end) { Matcher matcher = LINE_SEPARATOR_PATTERN.matcher(string); StringBuilder prefix = new StringBuilder(); int lastLineOffset = 0; while (matcher.find()) { if (matcher.end() > start) { break; } lastLineOffset = matcher.end(); prefix.append('\n'); } while (lastLineOffset++ < start) { prefix.append(' '); } return prefix + string.substring(start, end); }