The java substring () function deletes a specified string.
Public class main {
/**
* Case insensitive removal of a substring if it is at the end of a source string,
* Otherwise returns the source string.
*
* A <code> null </code> source string will return <code> null </code>.
* An empty ("") source string will return the empty string.
* A <code> null </code> search string will return the source string.
*
* <Pre>
* Stringutils. removeend (null, *) = null
* Stringutils. removeend ("", *) = ""
* Stringutils. removeend (*, null) = *
* Stringutils. removeend ("www.domain.com", ". com.") = "www.domain.com ."
* Stringutils. removeend ("www.domain.com", ". com") = "www. domain"
* Stringutils. removeend ("www.domain.com", "domain") = "www.domain.com"
* Stringutils. removeend ("abc", "") = "abc"
* </Pre>
*
* @ Param str the source string to search, may be null
* @ Param remove the string to search for (case insensitive) and remove, may be null
* @ Return the substring with the string removed if found,
* <Code> null </code> if null string input
* @ Since 2.4
*/
Public static string removeendignorecase (string str, string remove ){
If (isempty (str) | isempty (remove )){
Return str;
}
If (endswithignorecase (str, remove )){
Return str. substring (0, str. length ()-remove. length ());
}
Return str;
}
/**
* Case insensitive check if a string ends with a specified suffix.
*
* <Code> null </code> s are handled without exceptions. two <code> null </code>
* References are considered to be equal. the comparison is case insensitive.
*
* <Pre>
* Stringutils. endswithignorecase (null, null) = true
* Stringutils. endswithignorecase (null, "abcdef") = false
* Stringutils. endswithignorecase ("def", null) = false
* Stringutils. endswithignorecase ("def", "abcdef") = true
* Stringutils. endswithignorecase ("def", "abcdef") = false
* </Pre>
*
* @ See java. lang. string # endswith (string)
* @ Param str the string to check, may be null
* @ Param suffix the suffix to find, may be null
* @ Return <code> true </code> if the string ends with the suffix, case insensitive, or
* Both <code> null </code>
* @ Since 2.4
*/
Public static boolean endswithignorecase (string str, string suffix ){
Return endswith (str, suffix, true );
}
/**
* Check if a string ends with a specified suffix (optionally case insensitive ).
*
* @ See java. lang. string # endswith (string)
* @ Param str the string to check, may be null
* @ Param suffix the suffix to find, may be null
* @ Param ignorecase inidicates whether the compare shoshould ignore case
* (Case insensitive) or not.
* @ Return <code> true </code> if the string starts with the prefix or
* Both <code> null </code>
*/
Private static boolean endswith (string str, string suffix, boolean ignorecase ){
If (str = null | suffix = null ){
Return (str = null & suffix = null );
}
If (suffix. length ()> str. length ()){
Return false;
}
Int stroffset = str. length ()-suffix. length ();
Return str. regionmatches (ignorecase, stroffset, suffix, 0, suffix. length ());
}
// Empty checks
//-----------------------------------------------------------------------
/**
* Checks if a string is empty ("") or null.
*
* <Pre>
* Stringutils. isempty (null) = true
* Stringutils. isempty ("") = true
* Stringutils. isempty ("") = false
* Stringutils. isempty ("bob") = false
* Stringutils. isempty ("bob") = false
* </Pre>
*
* Note: this method changed in lang version 2.0.
* It no longer trims the string.
* That functionality is available in isblank ().
*
* @ Param str the string to check, may be null
* @ Return <code> true </code> if the string is empty or null
*/
Public static boolean isempty (string str ){
Return str = null | str. length () = 0;
}
}