Java tutorial
//package com.java2s; public class Main { public static String getMiddleString(String source, String start, String end) { int start_idx = source.indexOf(start) + start.length(); int end_idx = 0; if (end.isEmpty()) { end_idx = source.length(); } else { end_idx = source.indexOf(end, start_idx); if (end_idx <= 0) { end_idx = source.length(); } } if (start_idx <= 0 || end_idx <= 0 || end_idx <= start_idx) { return null; } return source.substring(start_idx, end_idx); } }