ReVo Blog


 
Replying to Random Snippets
Nickname
Post Icons
                                     

                                   

Code Buttons

         
           FFUpload  Huppy Pick colour HTML Editor Help
Enter your Post
(Check Message Length)

Clickable Smilies
:huh:^_^:o:;):P:D
:lol::B)::rolleyes:-_-<_<:)
:wub::angry::(:unsure::wacko::blink:
:ph34r::alienff::cry::sick::shifty::woot:
<3:XD:*_*:];P:XP:
(:=)X):D:>.<>_<
=_=:|:?3_3:p:;_;
^U^*^^*:=/::*::b::f:
Show All


  
 


Last 10 Posts [ In reverse order ]
.ReVo.Posted: 2/11/2014, 16:22
CODICE
private final static Pattern formatPattern = Pattern.compile("\\{(\\d+)\\}");
   public static String format(String string, Object... args) {
       Matcher matcher = formatPattern.matcher(string);
       StringBuffer builder = new StringBuffer();

       while (matcher.find()) {
           int index = Integer.parseInt(matcher.group(1));

           if (index < 0 || index > args.length) {
               continue;
           }

           matcher.appendReplacement(builder, args[index].toString());
       }
       matcher.appendTail(builder);

       return builder.toString();
   }


CODICE
System.out.println(format("Ciao {0}, come {1}?", "Mondo", "stai"));