Created
May 13, 2013 12:29
-
-
Save suxiaogang/5567973 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String replaceLast(String string, String toReplace, | |
String replacement) { | |
int pos = string.lastIndexOf(toReplace); | |
if (pos > -1) { | |
return string.substring(0, pos) | |
+ replacement | |
+ string.substring(pos + toReplace.length(), | |
string.length()); | |
} else { | |
return string; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment