public static void replaceLast ( StringBuffer haystack , String needle , String newNeedle ) { int idx = haystack . lastIndexOf ( needle ) ; if ( idx != - 1 ) { haystack . replace ( idx , idx + needle . length ( ) , newNeedle ) ; } }
replaces the last occurance of needle in haystack with newNeedle