Here you can find the source of substringGuarded(String s, int position, int count)
public static String substringGuarded(String s, int position, int count)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); public class Main { /**//from w ww . ja v a 2 s . c om * Like {@link String#substring(int)} but allows for the {@code count} * parameter to extend past the string's bounds. */ public static String substringGuarded(String s, int position, int count) { int sLength = s.length(); if (sLength - position <= count) { return position == 0 ? s : s.substring(position); } else { return s.substring(position, position + count); } } }