StrFormatter

Origin

I have always had a fondness for the string formatting in Slf4j, which accomplishes string formatting through simple placeholders like {}. So, referring to the source code of Slf4j, I created StrFormatter.

The quick use method for StrFormatter.format is StrUtil.format, and the latter is recommended.

Usage

// Usual usage
String result1 = StrFormatter.format("this is {} for {}", "a", "b");
Assert.assertEquals("this is a for b", result1);

// Escaping {}
String result2 = StrFormatter.format("this is \\{} for {}", "a", "b");
Assert.assertEquals("this is {} for a", result2);

// Escaping \
String result3 = StrFormatter.format("this is \\\\{} for {}", "a", "b");
Assert.assertEquals("this is \\a for b", result3);