public class TextFormatter extends Object
| Constructor and Description |
|---|
TextFormatter() |
| Modifier and Type | Method and Description |
|---|---|
static String |
format(CharSequence template,
Map<?,?> map,
boolean ignoreNull)
格式化文本
|
static String |
format(String template,
Object... args)
格式化字符串
此方法只是简单将占位符 {} 按照顺序替换为参数
如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可
例:
通常使用: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
|
static String |
format(String template,
String placeHolder,
Object... args)
格式化字符串
此方法只是简单将指定占位符 按照顺序替换为参数
如果想输出占位符使用 \\转义即可,如果想输出占位符之前的 \ 使用双转义符 \\\\ 即可
例:
通常使用: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
|
public static String format(String template, Object... args)
template - 字符串模板args - 参数列表public static String format(String template, String placeHolder, Object... args)
template - 字符串模板placeHolder - 占位符,例如{}args - 参数列表public static String format(CharSequence template, Map<?,?> map, boolean ignoreNull)
template - 文本模板,被替换的部分用 {key} 表示map - 参数值对ignoreNull - 是否忽略 null 值,忽略则 null 值对应的变量不被替换,否则替换为""Copyright © 2022. All rights reserved.