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


C# StringFormatter.Clear方法代码示例

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


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

示例1: FormatGuid

        public void FormatGuid()
        {
            var guid = Guid.NewGuid();
            var sb = new StringFormatter();

            sb.Append(guid);
            Assert.Equal(guid.ToString(), sb.ToString());
            sb.Clear();

            sb.Append(guid, 'D');
            Assert.Equal(guid.ToString("D"), sb.ToString());
            sb.Clear();

            sb.Append(guid, 'N');
            Assert.Equal(guid.ToString("N"), sb.ToString());
            sb.Clear();

            sb.Append(guid, 'B');
            Assert.Equal(guid.ToString("B"), sb.ToString());
            sb.Clear();

            sb.Append(guid, 'P');
            Assert.Equal(guid.ToString("P"), sb.ToString());
            sb.Clear();
        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:25,代码来源:PrimitiveFormattingTests-Guid.cs

示例2: FormatDateTimeG

        public void FormatDateTimeG()
        {
            var time = DateTime.UtcNow;
            var sb = new StringFormatter();

            sb.Append(time, 'G');
            Assert.Equal(time.ToString("G"), sb.ToString());
            sb.Clear();
        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:9,代码来源:PrimitiveFormattingTests-Time.cs

示例3: FormatTimeSpan

        public void FormatTimeSpan()
        {
            var time = new TimeSpan(1000, 23, 40, 30, 12345);
            var sb = new StringFormatter();

            sb.Append(time);
            Assert.Equal(time.ToString("", CultureInfo.InvariantCulture), sb.ToString());
            sb.Clear();
        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:9,代码来源:PrimitiveFormattingTests-Time.cs

示例4: FormatDateTimeO

        public void FormatDateTimeO()
        {
            var time = DateTime.UtcNow;
            var sb = new StringFormatter();

            sb.Append(time, 'O');
            Assert.Equal(time.ToString("O", CultureInfo.InvariantCulture), sb.ToString());
            sb.Clear();
        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:9,代码来源:PrimitiveFormattingTests-Time.cs

示例5: FormatDateTimeOffsetR

        public void FormatDateTimeOffsetR()
        {
            var time = DateTimeOffset.UtcNow;
            var sb = new StringFormatter(pool);

            sb.Append(time, 'R');
            Assert.Equal(time.ToString("R"), sb.ToString());
            sb.Clear();
        }
开发者ID:GrimDerp,项目名称:corefxlab,代码行数:9,代码来源:PrimitiveFormattingTests-Time.cs

示例6: CheckByte

        private void CheckByte(byte value, string format, string expected)
        {
            var formatter = new StringFormatter(pool);
            var parsed = Format.Parse(format);
            formatter.Clear();
            formatter.Append(value, parsed);
            var result = formatter.ToString();
            Assert.Equal(expected, result);

            var clrResult = value.ToString(format, CultureInfo.InvariantCulture);
            Assert.Equal(clrResult, result);
        }
开发者ID:kronic,项目名称:corefxlab,代码行数:12,代码来源:PrimitiveFormattingTests.cs

示例7: FloatFormatting

        public void FloatFormatting()
        {
            var sb = new StringFormatter(pool);

            sb.Append(Double.NaN);
            var result = sb.ToString();
            Assert.Equal("NaN", result);
            sb.Clear();

            sb.Append(Double.PositiveInfinity);
            result = sb.ToString();
            Assert.Equal("Infinity", result);
            sb.Clear();

            sb.Append(Double.NegativeInfinity);
            result = sb.ToString();
            Assert.Equal("-Infinity", result);
            sb.Clear();

            sb.Append(1.2);
            result = sb.ToString();
            Assert.Equal("1.2", result);
        }
开发者ID:Richard-FF,项目名称:corefxlab,代码行数:23,代码来源:PrimitiveFormattingTests.cs

示例8: FormatXPrecision

        public void FormatXPrecision()
        {
            var x = Format.Parse("x10");
            var X = Format.Parse("X10");

            var sb = new StringFormatter(pool);
            sb.Append((ulong)255, x);
            sb.Append((uint)255, X);
            Assert.Equal("00000000ff00000000FF", sb.ToString());

            sb.Clear();
            sb.Append((int)-1, X);
            Assert.Equal("00FFFFFFFF", sb.ToString());

            sb.Clear();
            sb.Append((int)-2, X);
            Assert.Equal("00FFFFFFFE", sb.ToString());
        }
开发者ID:Richard-FF,项目名称:corefxlab,代码行数:18,代码来源:PrimitiveFormattingTests.cs

示例9: FormatX

        public void FormatX()
        {
            var x = Format.Parse("x");
            var X = Format.Parse("X");

            var sb = new StringFormatter(pool);
            sb.Append((ulong)255, x);
            sb.Append((uint)255, X);
            Assert.Equal("ffFF", sb.ToString());

            sb.Clear();
            sb.Append((int)-1, X);
            Assert.Equal("FFFFFFFF", sb.ToString());

            sb.Clear();
            sb.Append((int)-2, X);
            Assert.Equal("FFFFFFFE", sb.ToString());
        }
开发者ID:Richard-FF,项目名称:corefxlab,代码行数:18,代码来源:PrimitiveFormattingTests.cs

示例10: CustomCultureFormat

        private void CustomCultureFormat()
        {
            StringFormatter sb = new StringFormatter(numbersToWrite * 3, pool);
            sb.FormattingData = CreateCustomCulture();

            timer.Restart();
            for (int itteration = 0; itteration < itterationsCulture; itteration++)
            {
                sb.Clear();
                for (int i = 0; i < numbersToWrite; i++)
                {
                    var next = (i % 128) + 101;
                    sb.Append(next);
                }
                var text = sb.ToString();
                if (text.Length != numbersToWrite * 3)
                {
                    throw new Exception("test failed");
                }
            }
            PrintTime();
        }
开发者ID:GrimDerp,项目名称:corefxlab,代码行数:22,代码来源:PerformanceTests.cs

示例11: CheckInt64

        private void CheckInt64(long value, string format, string expected, StringFormatter formatter)
        {
            var parsed = TextFormat.Parse(format);
            formatter.Clear();
            formatter.Append(value, parsed);
            var result = formatter.ToString();
            Assert.Equal(expected, result);

            var clrResult = value.ToString(format, CultureInfo.InvariantCulture);
            Assert.Equal(clrResult, result);
        }
开发者ID:AlexGhiondea,项目名称:corefxlab,代码行数:11,代码来源:PrimitiveFormattingTests.cs


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