zoukankan      html  css  js  c++  java
  • 定制字符串Format

       class Program 
    {
    static void Main()
    {
    StringBuilder sb = new StringBuilder();
    IFormatProvider f=new BoldInt();
    BoldInt b = new BoldInt();
    sb.AppendFormat(f, "{0} {1} {2:M}", "Xiaobai", 21, DateTime.Now);
    Console.WriteLine(sb.ToString());
    Console.ReadKey();
    }
    }
    sealed class BoldInt : IFormatProvider, ICustomFormatter
    {
    #region ICustomFormatter 成员

    string ICustomFormatter.Format(string format, object arg, IFormatProvider formatProvider)
    {
    string s;
    IFormattable formattable = arg as IFormattable;
    if (formattable == null) s = arg.ToString();
    else s = formattable.ToString(format, formatProvider);
    if (arg.GetType() == typeof(Int32))
    return "<B>"+s+"</B>";
    if(arg.GetType()==typeof(DateTime))
    return "<DateTime>"+s+"</DateTime>";
    if (arg.GetType() == typeof(String))
    return "<String>" + s + "</String>";
    return s;
    }

    #endregion
    #region IFormatProvider 成员
    object IFormatProvider.GetFormat(Type formatType)
    {
    if (formatType == typeof(ICustomFormatter)) return this;
    return Thread.CurrentThread.CurrentCulture.GetFormat(formatType);
    }
    #endregion
    }
  • 相关阅读:
    轮询算法
    随机算法
    加权随机算法
    平滑加权轮询算法
    预训练模型与Keras.applications.models权重资源地址
    多通道卷积操作解析
    Squeeze-and-Excitation Networks
    实验数据集概况
    Keras-图片预处理
    Keras常用层
  • 原文地址:https://www.cnblogs.com/smailxiaobai/p/2289237.html
Copyright © 2011-2022 走看看