Last active
August 29, 2015 14:21
-
-
Save marsyang1/a5d2d47078bb8633c64e to your computer and use it in GitHub Desktop.
String replaceLast
This file contains hidden or 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 String replaceAtLast(String source,final String matchChar char,final String replaceChar){ | |
StringBuilder b = new StringBuilder(source); | |
b.replace(source.lastIndexOf(char), source.lastIndexOf(char) + 1, replaceChar ); | |
source = b.toString(); | |
} | |
public String trimLast(String source ,final String matchChar) { | |
if (source.length() > 0 && source.charAt(str.length()-1) == matchChar) { | |
source = source.substring(0, source.length()-1); | |
} | |
return source; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment