String Formatter in GWT

前端 未结 12 680
生来不讨喜
生来不讨喜 2021-02-03 18:59

How do I format my string in GWT?

I made a method

  Formatter format = new Formatter();
    int matches = 0;
    Formatter formattedString = format.forma         


        
12条回答
  •  你的背包
    2021-02-03 19:53

    I'm not keen on abusing string manipulation for doing regexps' job, but, based on bodrin's solution, you can code:

    public static String format (String pattern, final Object ... args) {
        for (Object arg : args) {
            String part1 = pattern.substring(0,pattern.indexOf('{'));
            String part2 = pattern.substring(pattern.indexOf('}') + 1);
            pattern = part1 + arg + part2;
        }   
        return pattern;
    }
    

提交回复
热议问题