当前位置: 首页>>代码示例>>C#>>正文


C# StringFormatter.Format方法代码示例

本文整理汇总了C#中StringFormatter.Format方法的典型用法代码示例。如果您正苦于以下问题:C# StringFormatter.Format方法的具体用法?C# StringFormatter.Format怎么用?C# StringFormatter.Format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringFormatter的用法示例。


在下文中一共展示了StringFormatter.Format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompositeFormattingFormatStrings

        public void CompositeFormattingFormatStrings()
        {
            var formatter = new StringFormatter(pool);
            formatter.Format("Hello{0:x}{1:X}{2:G}", 10, 255, 3);

            Assert.Equal("HelloaFF3", formatter.ToString());
        }
开发者ID:nguerrera,项目名称:corefxlab,代码行数:7,代码来源:CompositeFormattingTests.cs

示例2: CompositeFormattingEscapingMissingStartBracket

        public void CompositeFormattingEscapingMissingStartBracket()
        {
            var pool = new ManagedBufferPool<byte>(1024);
            var formatter = new StringFormatter(pool);

            Assert.Throws<Exception>(() => formatter.Format("{0}}", 1));
        }
开发者ID:kronic,项目名称:corefxlab,代码行数:7,代码来源:CompositeFormattingTests.cs

示例3: CompositeFormattingEscaping

        public void CompositeFormattingEscaping()
        {
            var format = "}}a {0} b {0} c {{{0}}} d {{e}} {{";
            var formatter = new StringFormatter(pool);
            formatter.Format(format, 1);

            Assert.Equal(string.Format(CultureInfo.InvariantCulture, format, 1), formatter.ToString());
        }
开发者ID:nguerrera,项目名称:corefxlab,代码行数:8,代码来源:CompositeFormattingTests.cs

示例4: CompositeFormattingFormatStrings

        public void CompositeFormattingFormatStrings()
        {
            var pool = new ManagedBufferPool<byte>(1024);
            var formatter = new StringFormatter(pool);
            formatter.Format("Hello{0:x}{1:X}{2:G}", 10, 255, 3);

            Assert.Equal("HelloaFF3", formatter.ToString());
        }
开发者ID:kronic,项目名称:corefxlab,代码行数:8,代码来源:CompositeFormattingTests.cs

示例5: CompositeFormattingBasics

 public void CompositeFormattingBasics()
 {
     var time = DateTime.UtcNow;
     using (var formatter = new StringFormatter(pool))
     {
         formatter.Format("{2} - Error {0}. File {1} not found.", 404, "index.html", time);
         Assert.Equal(time.ToString("G") + " - Error 404. File index.html not found.", formatter.ToString());
     }
 }
开发者ID:TerabyteX,项目名称:corefxlab,代码行数:9,代码来源:CompositeFormattingTests.cs

示例6: CompositeFormattingBasics

        public void CompositeFormattingBasics()
        {
            var time = DateTime.UtcNow;
            var pool = new ManagedBufferPool<byte>(1024);
            var formatter = new StringFormatter(pool);
            formatter.Format("{2} - Error {0}. File {1} not found.", 404, "index.html", time);

            Assert.Equal(time.ToString("G") + " - Error 404. File index.html not found.", formatter.ToString());
        }
开发者ID:kronic,项目名称:corefxlab,代码行数:9,代码来源:CompositeFormattingTests.cs

示例7: CompositeFormattingBasics

 public void CompositeFormattingBasics()
 {
     var time = new DateTime(2016, 2, 9, 4, 1, 59, DateTimeKind.Utc);
     using (var formatter = new StringFormatter(pool))
     {
         formatter.Format("{2:G} - Error {0}. File {1} not found.", 404, "index.html", time);
         Assert.Equal("2/9/2016 4:01:59 AM - Error 404. File index.html not found.", formatter.ToString());
     }
 }
开发者ID:nguerrera,项目名称:corefxlab,代码行数:9,代码来源:CompositeFormattingTests.cs

示例8: StringFormatter_CanFormatDoubleArgumentWithDecimalsCommand

        public void StringFormatter_CanFormatDoubleArgumentWithDecimalsCommand()
        {
            var formatter = new StringFormatter();
            var buffer    = new StringBuilder();

            formatter.Reset();
            formatter.AddArgument(123.456789);
            formatter.Format("this is a Double value: {0:decimals:2}", buffer);

            TheResultingString(buffer).ShouldBe("this is a Double value: 123.46");
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:11,代码来源:StringFormatterTest.cs

示例9: StringFormatter_CanFormatCharArgument

        public void StringFormatter_CanFormatCharArgument()
        {
            var formatter = new StringFormatter();
            var buffer    = new StringBuilder();

            formatter.Reset();
            formatter.AddArgument('Z');
            formatter.Format("this is a Char value: {0}", buffer);

            TheResultingString(buffer).ShouldBe("this is a Char value: Z");
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:11,代码来源:StringFormatterTest.cs

示例10: StringFormatter_CanFormatByteArgument

        public void StringFormatter_CanFormatByteArgument()
        {
            var formatter = new StringFormatter();
            var buffer    = new StringBuilder();

            formatter.Reset();
            formatter.AddArgument((Byte)123);
            formatter.Format("this is a Byte value: {0}", buffer);

            TheResultingString(buffer).ShouldBe("this is a Byte value: 123");
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:11,代码来源:StringFormatterTest.cs

示例11: StringFormatter_CanFormatDoubleArgument

        public void StringFormatter_CanFormatDoubleArgument()
        {
            var formatter = new StringFormatter();
            var buffer    = new StringBuilder();

            formatter.Reset();
            formatter.AddArgument(123.45);
            formatter.Format("this is a Double value: {0}", buffer);

            TheResultingString(buffer).ShouldBe("this is a Double value: 123.45000");
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:11,代码来源:StringFormatterTest.cs

示例12: StringFormatter_CanFormatStringArgument

        public void StringFormatter_CanFormatStringArgument()
        {
            var formatter = new StringFormatter();
            var buffer    = new StringBuilder();

            formatter.Reset();
            formatter.AddArgument("world");
            formatter.Format("hello {0}", buffer);

            TheResultingString(buffer).ShouldBe("hello world");
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:11,代码来源:StringFormatterTest.cs

示例13: StringFormatter_CanFormatBooleanArgument

        public void StringFormatter_CanFormatBooleanArgument()
        {
            var formatter = new StringFormatter();
            var buffer    = new StringBuilder();

            formatter.Reset();
            formatter.AddArgument(true);
            formatter.AddArgument(false);
            formatter.Format("this is {0} and this is {1}", buffer);

            TheResultingString(buffer).ShouldBe("this is True and this is False");
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:12,代码来源:StringFormatterTest.cs

示例14: __repr__

        public static string __repr__(CodeContext/*!*/ context, double self) {
            if (Double.IsNaN(self)) {
                return "nan";
            }

            // first format using Python's specific formatting rules...
            StringFormatter sf = new StringFormatter(context, "%.17g", self);
            sf._TrailingZeroAfterWholeFloat = true;
            string res = sf.Format();
            if (LiteralParser.ParseFloat(res) == self) {
                return res;
            }

            // if it's not round trippable though use .NET's round-trip format
            return self.ToString("R", CultureInfo.InvariantCulture);
        }
开发者ID:follesoe,项目名称:ironruby,代码行数:16,代码来源:FloatOps.cs

示例15: __str__

 public static string __str__(CodeContext/*!*/ context, double x) {
     StringFormatter sf = new StringFormatter(context, "%.12g", x);
     sf._TrailingZeroAfterWholeFloat = true;
     return sf.Format();
 }
开发者ID:follesoe,项目名称:ironruby,代码行数:5,代码来源:FloatOps.cs


注:本文中的StringFormatter.Format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。