replaceSuffix function

String replaceSuffix(
  1. String text,
  2. String oldSuffix,
  3. String newSuffix
)

Implementation

String replaceSuffix(
    String text,
    String oldSuffix,
    String newSuffix
    )
{
    if ( text.endsWith( oldSuffix ) )
    {
        return text.substring( 0, text.length - oldSuffix.length ) + newSuffix;
    }
    else
    {
        return text;
    }
}