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


C# StringBuilder.Substring方法代码示例

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


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

示例1: Main

        public static void Main()
        {
            Console.Title = "StringBuilder substring test";

                                          //Indexes 012345678901234
            StringBuilder test = new StringBuilder("Test message!!!");

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("The whole message -> ");

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(test);    // The whole message
            
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("\nSubstring from index 5 with length 7 -> ");

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(test.Substring(5, 7)); // This will print message
            
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("Substring from index 0 with length 4 -> ");

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine(test.Substring(0, 4)); // Thisi will print Test
            
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("Substring from index 5 without length -> ");

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(test.Substring(5));    // This will print message!!!

            Console.WriteLine();
            Console.ResetColor();
        }
开发者ID:nikolay-radkov,项目名称:Telerik-Academy,代码行数:34,代码来源:Extensions.cs

示例2: Main

        static void Main(string[] args)
        {
            //test extension methods for StringBuilder
            StringBuilder sb = new StringBuilder();
            sb.Append("Once a type is defined and compiled into an assembly its definition is, more or less, final");

            //add substring extension method, from index to the end
            StringBuilder substringToEnd = sb.Substring(5);
            Console.WriteLine(substringToEnd.ToString());

            //the extension method from the exercise task
            StringBuilder substring = sb.Substring(5, 6);
            Console.WriteLine(substring.ToString());

            //test IEnumerable extension methods
            List<double> numbers = new List<double>();
            numbers.Add(6.0);
            numbers.Add(10.0);
            numbers.Add(199.5);
            numbers.Add(0.5);
            numbers.Add(7.0);
            numbers.Add(20.0);

            double minElem = numbers.Min();
            double maxElem = numbers.Max();
            double sum = numbers.Sum();
            double average = numbers.Average();
            double product = numbers.Product();

            Console.WriteLine("Min element: " + minElem + "\nMax element: " + maxElem);
            Console.WriteLine("Sum : " + sum);
            Console.WriteLine("Average : " + average);
            Console.WriteLine("Product : " + product);

        }
开发者ID:jesusico83,项目名称:Telerik,代码行数:35,代码来源:ExtensionMethodsTester.cs

示例3: Main

        static void Main()
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder test0 = sb.Substring(0, 0);

            sb.Append("It's a spring out there!");
            Console.WriteLine("Source string builder: {0}", sb);
            Console.WriteLine();

            StringBuilder sbPart = sb.Substring(7, 6);
            Console.WriteLine("sb.Substring(7, 6) is processed.");
            Console.WriteLine("Result string builder: {0}", sbPart);
            Console.WriteLine();

            sbPart = sb.Substring(0, 1);
            Console.WriteLine("sb.Substring(0, 1) is processed.");
            Console.WriteLine("Result string builder: {0}", sbPart);
            Console.WriteLine();

            sbPart = sb.Substring(0, sb.Length);
            Console.WriteLine("sb.Substring(0, sb.Length) is processed.");
            Console.WriteLine("Result string builder: {0}", sbPart);
            Console.WriteLine();

            sbPart = sb.Substring(1, sb.Length - 1);
            Console.WriteLine("sb.Substring(1, sb.Length - 1) is processed.");
            Console.WriteLine("Result string builder: {0}", sbPart);
            Console.WriteLine();
        }
开发者ID:ValMomchilova,项目名称:TelerikAcademyHomeWorks,代码行数:29,代码来源:StringBuilderHelperTest.cs

示例4: Main

 static void Main()
 {
     StringBuilder testExtension = new StringBuilder();
     testExtension.Append("This tests the substring extension method");
     Console.WriteLine(testExtension.Substring(15));
     Console.WriteLine(testExtension.Substring(5,4));
 }
开发者ID:sylviapsh,项目名称:19.ExtensionMethodsDelegatesLambdaLINQ,代码行数:7,代码来源:ExtensionOfSubstringTest.cs

示例5: Main

 static void Main()
 {
     StringBuilder sb = new StringBuilder("abrakadabra");
     
     Console.WriteLine(sb.Substring(4));
     Console.WriteLine(sb.Substring(2,8));
 }
开发者ID:hristo11111,项目名称:TelerikAcademy-HristoBratanov,代码行数:7,代码来源:Program.cs

示例6: Main

    static void Main()
    {
        StringBuilder text = new StringBuilder();
        text.Append("123456789");

        Console.WriteLine(text.Substring(3, 3));
        Console.WriteLine(text.Substring(3));
    }
开发者ID:vassil,项目名称:CSharp,代码行数:8,代码来源:01.SubstringExtension.cs

示例7: Main

        static void Main()
        {
            StringBuilder test = new StringBuilder();
            test.Append("This is the test for the substring extension!");

            Console.WriteLine("Taking a substring from text with given index and length: " + test.Substring(12, 4));
            Console.WriteLine("Taking a substring from text with given only index: " + test.Substring(12));
        }
开发者ID:ivanvasilev,项目名称:Telerik-Academy-Homeworks,代码行数:8,代码来源:ProgramTest.cs

示例8: Main

        static void Main()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("some text goes here");

            Console.WriteLine(sb.Substring(5, 4)); // "text"
            Console.WriteLine(sb.Substring(10, sb.Length - 10)); // "goes here"
        }
开发者ID:Rokata,项目名称:TelerikAcademy,代码行数:8,代码来源:StringBuilderExtensionDemo.cs

示例9: Main

 internal static void Main()
 {
     var str = new StringBuilder();
     str.Append("Hello my frind. Kefish sa na sun?");
     str.Substring(5);
     Console.WriteLine(str.Substring(3, 5).ToString());
     Console.WriteLine(str.Substring(5).ToString());
 }
开发者ID:VyaraGGeorgieva,项目名称:TelerikAcademy,代码行数:8,代码来源:Test.cs

示例10: Main

 static void Main()
 {
     StringBuilder test = new StringBuilder("Hello Extension Methods");
     StringBuilder result = test.Substring(1, 3);
     Console.WriteLine(result);
     result = test.Substring(2);
     Console.WriteLine(result);
 }
开发者ID:damy90,项目名称:Telerik-all,代码行数:8,代码来源:Test.cs

示例11: Main

 static void Main(string[] args)
 {
     StringBuilder test = new StringBuilder("niso");
     Console.WriteLine(test.Substring(0,2));
     Console.WriteLine(test.Substring(2));
       
    
 }
开发者ID:nikimoto,项目名称:thegodmode.github.com,代码行数:8,代码来源:01.TestStringBuilder.cs

示例12: Main

    static void Main()
    {
        StringBuilder a = new StringBuilder();
        a.Append("Musaka s tarator");
        Console.WriteLine(a.Substring(4));

        Console.WriteLine(a.Substring(0, 3));

    }
开发者ID:ScreeM92,项目名称:Software-University,代码行数:9,代码来源:TestClass.cs

示例13: Main

        public static void Main()
        {
            var test = new StringBuilder("Testing an extension method Substring for the class StringBuilder");
            var firstTest = test.Substring(0, 37);
            var secondTest = test.Substring(38);

            Console.WriteLine(firstTest);
            Console.WriteLine(secondTest);
        }
开发者ID:b-slavov,项目名称:Telerik-Software-Academy,代码行数:9,代码来源:Startup.cs

示例14: Main

        public static void Main()
        {
            StringBuilder input = new StringBuilder();
            input.Append("Testing StringBuilder!");

            StringBuilder result = input.Substring(8);
            Console.WriteLine(result);
            result = input.Substring(10, 3);
            Console.WriteLine(result);
        }
开发者ID:AsiaBecheva,项目名称:OOP,代码行数:10,代码来源:TestStringBuilder.cs

示例15: Main

 public static void Main()
 {
     StringBuilder test = new StringBuilder();
     test.Append("Hello, C#!");
     Console.WriteLine("We are given string:{0}", test);
     StringBuilder testResult = test.Substring(7);
     Console.WriteLine("Substring starting from character at positon 7:"+testResult);
     testResult = test.Substring(0, 5);
     Console.WriteLine("Substring starting at position zero that has length 5 characters:"+testResult);
 }
开发者ID:plwh,项目名称:TelerikHomework,代码行数:10,代码来源:StringBuilderSubstring.cs


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