01: package com.etymon.pj.util;
02:
03: public final class StringUtil {
04:
05: public static String sprintf(String template, String[] args) {
06: if (args == null) {
07: return template;
08: }
09: StringBuffer sb = new StringBuffer();
10: int start = 0;
11: int index;
12: int x = 0;
13: while ((x < args.length)
14: && ((index = template.indexOf("%s", start)) != -1)) {
15: // allow \%s to escape
16: if ((index == 0) || (template.charAt(index - 1) != '\\')) {
17: sb.append(template.substring(start, index));
18: sb.append(args[x]);
19: start = index + 2;
20: }
21: }
22: sb.append(template.substring(start));
23: return sb.toString();
24: }
25:
26: }
|