static public String safeSubstring(String text,int beginIndex,int endIndexExclusive){
  if (text == null) {
    return null;
  }
  int textLength=text.length();
  if (beginIndex < 0) {
    beginIndex=0;
  }
  if (endIndexExclusive < 0) {
    endIndexExclusive=0;
  }
  if (endIndexExclusive > textLength) {
    endIndexExclusive=textLength;
  }
  if (beginIndex > endIndexExclusive) {
    beginIndex=endIndexExclusive;
  }
  if (beginIndex == endIndexExclusive) {
    return "";
  }
  return text.substring(beginIndex,endIndexExclusive);
}

static public String safeSubstring ( String text , int beginIndex , int endIndexExclusive ) { if ( text == null ) { return null ; } int textLength = text . length ( ) ; if ( beginIndex < 0 ) { beginIndex = 0 ; } if ( endIndexExclusive < 0 ) { endIndexExclusive = 0 ; } if ( endIndexExclusive > textLength ) { endIndexExclusive = textLength ; } if ( beginIndex > endIndexExclusive ) { beginIndex = endIndexExclusive ; } if ( beginIndex == endIndexExclusive ) { return "" ; } return text . substring ( beginIndex , endIndexExclusive ) ; }
safesubstring , this is a version of the substring function which is guaranteed to never throw an exception . if the supplied string is null then this will return null . if the beginindex or endindexexclusive are out of range for the string , then the indexes will be compressed to fit within the bounds of the supplied string . if the beginindex is greater than or equal to endindexexclusive , then this will return an empty string .
