StringBuilder.AppendFormat 的高级格式化规则

发布于 2024-09-16 10:51:45 字数 691 浏览 4 评论 0原文

我在此网站上看到了一个说明AppendFormat用法的StringBuilder代码示例:

using System;
using System.Text;

class Program
{
    static int[] _v = new int[]
    {
        1,
        4,
        6
    };

    static void Main()
    {
        StringBuilder b = new StringBuilder();
        foreach (int v in _v)
        {
            b.AppendFormat("int: {0:0.0}{1}", v,
                Environment.NewLine);
        }
        Console.WriteLine(b.ToString());
    }
}
=== 程序输出 ===

整数:1.0
整数:4.0
积分:6.0

在哪里可以找到有关字符串格式化的高级规则的文档?

I've seen on this site a StringBuilder code sample illustrating AppendFormat usage:

using System;
using System.Text;

class Program
{
    static int[] _v = new int[]
    {
        1,
        4,
        6
    };

    static void Main()
    {
        StringBuilder b = new StringBuilder();
        foreach (int v in _v)
        {
            b.AppendFormat("int: {0:0.0}{1}", v,
                Environment.NewLine);
        }
        Console.WriteLine(b.ToString());
    }
}
=== Output of the program ===

int: 1.0
int: 4.0
int: 6.0

Where can I find documentation on those advanced rules for string formatting?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

请爱~陌生人 2024-09-23 10:51:45

您是否在寻找这个

Are you looking for this ?

世界等同你 2024-09-23 10:51:45

您可以首先查看 MSDN 上的复合格式文章。从那里您将找到 数字 和 < a href="http://msdn.microsoft.com/en-us/library/az4se3k1.aspx" rel="nofollow noreferrer">日期,以及指向 数字日期

You can start by checking the Composite Formatting article at MSDN. From there you will find links to standard format strings for numbers and dates, as well as links to the custom format strings for both numbers and dates.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文