类 StrFormatter

java.lang.Object
cn.dev33.satoken.util.StrFormatter

public class StrFormatter extends Object
字符串格式化工具

本工具类 copy 自 Hutool: https://github.com/dromara/hutool/blob/v5-master/hutool-core/src/main/java/cn/hutool/core/text/StrFormatter.java

作者:
Looly
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    static char
     
    static String
    占位符
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static String
    format(String strPattern, 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
    static String
    formatWith(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

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

    • EMPTY_JSON

      public static String EMPTY_JSON
      占位符
    • C_BACKSLASH

      public static char C_BACKSLASH
  • 构造器详细资料

    • StrFormatter

      public StrFormatter()
  • 方法详细资料

    • format

      public static String format(String strPattern, 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
      参数:
      strPattern - 字符串模板
      argArray - 参数列表
      返回:
      结果
    • formatWith

      public static String formatWith(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
      参数:
      strPattern - 字符串模板
      placeHolder - 占位符,例如{}
      argArray - 参数列表
      返回:
      结果
      从以下版本开始:
      5.7.14