1 19 20 package edu.umd.cs.findbugs.util; 21 22 25 public class Strings { 26 27 37 public static String replace(String source, String find, String repl) { 38 40 int j = source.indexOf(find); if (j < 0) return source; final int findLen = find.length(); 43 if (findLen <= 0) throw new IllegalArgumentException ("unable to replace all occurrences of the empty String"); 44 int anchor = 0; 45 StringBuffer sb = new StringBuffer (source.length()+repl.length()); while (j >= 0) { 47 sb.append(source.substring(anchor, j)); 48 sb.append(repl); 49 anchor = j+findLen; 50 j = source.indexOf(find, anchor); 51 } 52 sb.append(source.substring(anchor)); 53 return sb.toString(); 54 } 55 56 64 public static String toString(final Object [] a) { 65 if (a == null) return "null"; 66 int max = a.length - 1; 67 StringBuffer sb = new StringBuffer ("["); 68 for (int j=0; j <= max; j+=1) { 69 sb.append(String.valueOf(a[j])); 70 if (j < max) sb.append(','); } 72 sb.append(']'); 73 return sb.toString(); 74 } 75 76 82 public static String trimComma(String s) { 83 if (s.endsWith(",")) { 84 s = s.substring(0, s.length() - 1); 85 } 86 return s; 87 } 88 89 } 90 | Popular Tags |