【问题标题】:String.Format with custom Formatter带有自定义格式化程序的 String.Format
【发布时间】:2016-05-31 16:46:02
【问题描述】:

我有一个自定义字符串格式化程序,我想在使用标准格式化程序后使用它,我的自定义字符串格式化程序使用 {0:SP} 作为其格式前缀。

我想做的是让这个简单的例子工作

  String.Format("{{0}:SP}" , 1)

我遇到了一个异常:

base: {System.FormatException: 输入字符串不正确 格式。

这样做的正确方法是什么?

【问题讨论】:

    标签: c# string string-formatting stringbuilder


    【解决方案1】:
    String.Format("{{{0}:SP}}" , 1)
    

    这很烦人,但你必须在里面放两个 如果你想显示{1:SP}

    Here 是原始答案

    【讨论】:

      猜你喜欢
      • 2021-12-04
      • 1970-01-01
      • 1970-01-01
      • 2012-04-10
      • 2018-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多