Akom's Tech Ruminations

Various tech outbursts - code and solutions to practical problems

Code and Hacks Converting .NET String.format pattern to Java with a regular expression

Posted by Admin • Monday, September 10. 2012 • Category: Code and Hacks
For this exercise in futility, I want to accomplish the following:

From .NET: "Hello, {0} Today is the {1} day"  
To JAVA: "Hello, {%1$s} Today is the {%2$s} day"


Note that a simple regex would work here if it weren't for the zero-based indexes. We need to increment the number as well do a pattern replace. Since I'm comfortable with PHP, I took a sample from preg_replace_callback description and modified it accordingly:

Continue reading "Converting .NET String.format pattern to Java with a regular expression"