How do I format my string in GWT?
I made a method
Formatter format = new Formatter();
int matches = 0;
Formatter formattedString = format.forma
another very very simple replacement for java.text.MessageFormat.format() :
public static String format(final String format, final Object... args) {
StringBuilder sb = new StringBuilder();
int cur = 0;
int len = format.length();
while (cur < len) {
int fi = format.indexOf('{', cur);
if (fi != -1) {
sb.append(format.substring(cur, fi));
int si = format.indexOf('}', fi);
if (si != -1) {
String nStr = format.substring(fi + 1, si);
int i = Integer.parseInt(nStr);
sb.append(args[i]);
cur = si + 1;
} else {
sb.append(format.substring(fi));
break;
}
} else {
sb.append(format.substring(cur, len));
break;
}
}
return sb.toString();
}