Class StringFormatter
java.lang.Object
org.miaixz.bus.core.text.placeholder.StringFormatter
字符串格式化工具
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclear()清空缓存static Stringformat(CharSequence template, Map<?, ?> map, boolean ignoreNull) 格式化文本,使用 {varName} 占位 map = {a: "aValue", b: "bValue"} format("{a} and {b}", map) = aValue and bValuestatic String格式化字符串 此方法只是简单将占位符 {} 按照顺序替换为参数 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可 例: 通常使用:format("this is {} for {}", "a", "b") = this is a for b 转义{}: format("this is \\{} for {}", "a", "b") = this is {} for a 转义\: format("this is \\\\{} for {}", "a", "b") = this is \a for bstatic StringformatWith(String strPattern, String placeHolder, Object... argArray) 格式化字符串 此方法只是简单将指定占位符 按照顺序替换为参数 如果想输出占位符使用 \\转义即可,如果想输出占位符之前的 \ 使用双转义符 \\\\ 即可 例: 通常使用:format("this is {} for {}", "{}", "a", "b") = this is a for b 转义{}: format("this is \\{} for {}", "{}", "a", "b") = this is {} for a 转义\: format("this is \\\\{} for {}", "{}", "a", "b") = this is \a for b
-
Constructor Details
-
StringFormatter
public StringFormatter()
-
-
Method Details
-
format
格式化字符串 此方法只是简单将占位符 {} 按照顺序替换为参数 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可 例: 通常使用:format("this is {} for {}", "a", "b") = this is a for b 转义{}: format("this is \\{} for {}", "a", "b") = this is {} for a 转义\: format("this is \\\\{} for {}", "a", "b") = this is \a for b- Parameters:
strPattern- 字符串模板argArray- 参数列表- Returns:
- 结果
-
formatWith
格式化字符串 此方法只是简单将指定占位符 按照顺序替换为参数 如果想输出占位符使用 \\转义即可,如果想输出占位符之前的 \ 使用双转义符 \\\\ 即可 例: 通常使用:format("this is {} for {}", "{}", "a", "b") = this is a for b 转义{}: format("this is \\{} for {}", "{}", "a", "b") = this is {} for a 转义\: format("this is \\\\{} for {}", "{}", "a", "b") = this is \a for b- Parameters:
strPattern- 字符串模板placeHolder- 占位符,例如{}argArray- 参数列表- Returns:
- 结果
-
format
格式化文本,使用 {varName} 占位 map = {a: "aValue", b: "bValue"} format("{a} and {b}", map) = aValue and bValue- Parameters:
template- 文本模板,被替换的部分用 {data} 表示map- 参数值对ignoreNull- 是否忽略null值,忽略则null值对应的变量不被替换,否则替换为""- Returns:
- 格式化后的文本
-
clear
public static void clear()清空缓存
-