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


C# StringFormatter.ToString方法代码示例

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


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

 public void CustomTypeToString()
 {
     var sb = new StringFormatter();
     sb.Append(new Age(56));
     sb.Append(new Age(14, inMonths: true));
     Assert.Equal(sb.ToString(), "56y14m");
 }
开发者ID:AlexGhiondea,项目名称:corefxlab,代码行数:7,代码来源:CustomTypeFormatting.cs

示例3: 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

示例4: CustomCulture

        public void CustomCulture()
        {
            var sb = new StringFormatter(ArrayPool<byte>.Shared);
            sb.FormattingData = FormattingDataProvider.CreateFormattingData("pl-PL");

            sb.Append(-10000, Format.Parse('N'));
            Assert.Equal("-10\u00A0000,00", sb.ToString()); // \u00A0 is a space group separator
        }
开发者ID:nguerrera,项目名称:corefxlab,代码行数:8,代码来源:BasicTests.cs

示例5: CustomCulture

        public void CustomCulture()
        {
            var sb = new StringFormatter();
            sb.Encoding = Culture5;

            sb.Append(-1234567890);
            Assert.Equal("_?BBBBBCCCCCDDDDDEEEEEFFFFFGGGGGHHHHHIIIIIJJJJJAAAAA", sb.ToString());
        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:8,代码来源:CustomCulture.cs

示例6: CustomCulture

        public void CustomCulture()
        {
            var sb = new StringFormatter();
            sb.Encoding = EncodingProvider.CreateEncoding("pl-PL");

            sb.Append(-10000, TextFormat.Parse('N'));
            Assert.Equal("-10\u00A0000,00", sb.ToString()); // \u00A0 is a space group separator
        }
开发者ID:AlexGhiondea,项目名称:corefxlab,代码行数:8,代码来源:BasicTests.cs

示例7: 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

示例8: 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

示例9: CustomCulture

        public void CustomCulture()
        {
            var pool = new ManagedBufferPool<byte>(1024);
            var sb = new StringFormatter(pool);
            sb.FormattingData = FormattingDataProvider.CreateFormattingData("pl-PL");

            sb.Append(-10000, Format.Parse('N'));
            Assert.Equal("-10\u00A0000,00", sb.ToString()); // \u00A0 is a space group separator
        }
开发者ID:SmartCloudAI,项目名称:corefxlab,代码行数:9,代码来源:BasicTests.cs

示例10: 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

示例11: 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

示例12: BasicStringFormatter

 public void BasicStringFormatter()
 {
     var sb = new StringFormatter();
     sb.Append("hi");
     sb.Append(1);
     sb.Append("hello");
     sb.Append((sbyte)-20);
     Assert.Equal("hi1hello-20", sb.ToString());
 }
开发者ID:AlexGhiondea,项目名称:corefxlab,代码行数:9,代码来源:PrimitiveFormattingTests.cs

示例13: 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

示例14: CheckTimeSpan

 public void CheckTimeSpan(TimeSpan value, string format)
 {
     var parsed = Format.Parse(format);
     var formatter = new StringFormatter(pool);
     formatter.Append(value, parsed);
     var result = formatter.ToString();
     var clrResult = value.ToString(format, CultureInfo.InvariantCulture);
     Assert.Equal(clrResult, result);
 }
开发者ID:GrimDerp,项目名称:corefxlab,代码行数:9,代码来源:TimeSpanFormattingTests.Generated.cs

示例15: 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


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