C# Unity占位符的使用以及标准数字字符串格式化

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_40229737/article/details/100747174

  占位符的使用

  string str = string.Format("我的名字叫{0},我喜欢{1}","小红","唱歌");
          // 我的名字叫小红,我喜欢唱歌

 

标准数字字符串格式化

C#打印结果

 Unity打印结果

  string str = string.Format("金额:{0:c}", 10);
        string str1 = string.Format("金额:{0:d2}", 5);
        string str2 = string.Format("金额:{0:f1}",1.26);
        string str3 = string.Format("金额:{0:p0}", 0.134);
        Debug.Log(str);//金额:¥10.00
        Debug.Log(str1);//
        Debug.Log(str2);//
        Debug.Log(str3);//金额:13%

猜你喜欢

转载自blog.csdn.net/qq_40229737/article/details/100747174
今日推荐