X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FStringUtils.java;h=1c67c92ea0322ba0b3c0029265347e0e460fb48e;hb=a7169b1c72607f3c9357195b4999869650a2a891;hp=adba947c1885820cf17e539602c161478c499d73;hpb=01f8ff469a507604ed961418f7c80f9b245e60ca;p=jalview.git diff --git a/src/jalview/util/StringUtils.java b/src/jalview/util/StringUtils.java index adba947..1c67c92 100644 --- a/src/jalview/util/StringUtils.java +++ b/src/jalview/util/StringUtils.java @@ -597,4 +597,42 @@ public class StringUtils } return index; } + + /* + * 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) + { + int pos = string.lastIndexOf(toReplace); + if (pos > -1) + { + return new StringBuilder().append(string.substring(0, pos)) + .append(replacement) + .append(string.substring(pos + toReplace.length())) + .toString(); + } + else + { + return string; + } + + } + + /* + * return the maximum length of a List of Strings + */ + public static int maxLength(List l) + { + int max = 0; + for (String s : l) + { + if (s == null) + continue; + if (s.length() > max) + max = s.length(); + } + return max; + } }