Replace Last Occurrence of a character in a string [duplicate]
问题 This question already has an answer here: Replace last part of string 11 answers I am having a string like this "Position, fix, dial" I want to replace the last double quote(") with escape double quote(\") The result of the string is to be "Position, fix, dial\" How can I do this. I am aware of replacing the first occurrence of the string. but don't know how to replace the last occurrence of a string 回答1: String str = "\"Position, fix, dial\""; int ind = str.lastIndexOf("\""); if( ind>=0 )