git://source.jalview.org
/
jalview.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
JAL-629 improved comment and return speed of StringUtils.replaceLast()
[jalview.git]
/
src
/
jalview
/
util
/
StringUtils.java
diff --git
a/src/jalview/util/StringUtils.java
b/src/jalview/util/StringUtils.java
index
7e1b8ad
..
efaf3e2
100644
(file)
--- a/
src/jalview/util/StringUtils.java
+++ b/
src/jalview/util/StringUtils.java
@@
-600,6
+600,7
@@
public class StringUtils
/*
* implementation of String.replaceLast.
/*
* implementation of String.replaceLast.
+ * Replaces only the last occurrence of toReplace in string with replacement.
*/
public static String replaceLast(String string, String toReplace,
String replacement)
*/
public static String replaceLast(String string, String toReplace,
String replacement)
@@
-607,8
+608,10
@@
public class StringUtils
int pos = string.lastIndexOf(toReplace);
if (pos > -1)
{
int pos = string.lastIndexOf(toReplace);
if (pos > -1)
{
- return string.substring(0, pos) + replacement
- + string.substring(pos + toReplace.length());
+ return new StringBuilder().append(string.substring(0, pos))
+ .append(replacement)
+ .append(string.substring(pos + toReplace.length()))
+ .toString();
}
else
{
}
else
{