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:
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:
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"