public static String replaceLast ( String s , char sub , char with ) { int index = s . lastIndexOf ( sub ) ; if ( index == - 1 ) { return s ; } char [ ] str = s . toCharArray ( ) ; str [ index ] = with ; return new String ( str ) ; }
Replaces the very last occurrence of a character in a string .