Java tutorial
//package com.java2s; public class Main { public static String middle(String input, int index, int count) { if (input.isEmpty()) { return ""; } count = (count > input.length() - index + 1) ? input.length() - index + 1 : count; return input.substring(index - 1, index + count - 1); } }