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();
        }
        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);

        }
        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();
        }
 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));
 }
 static void Main()
 {
     StringBuilder sb = new StringBuilder("abrakadabra");
     
     Console.WriteLine(sb.Substring(4));
     Console.WriteLine(sb.Substring(2,8));
 }
示例#6
0
    static void Main()
    {
        StringBuilder text = new StringBuilder();
        text.Append("123456789");

        Console.WriteLine(text.Substring(3, 3));
        Console.WriteLine(text.Substring(3));
    }
        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));
        }
        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"
        }
示例#9
0
 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());
 }
示例#10
0
 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);
 }
 static void Main(string[] args)
 {
     StringBuilder test = new StringBuilder("niso");
     Console.WriteLine(test.Substring(0,2));
     Console.WriteLine(test.Substring(2));
       
    
 }
示例#12
0
    static void Main()
    {
        StringBuilder a = new StringBuilder();
        a.Append("Musaka s tarator");
        Console.WriteLine(a.Substring(4));

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

    }
        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);
        }
示例#14
0
        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);
        }
 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);
 }
示例#16
0
        static void Main(string[] args)
        {
            StringBuilder builder = new StringBuilder("Sralo meche na pyteche!");
            Console.WriteLine(builder.Substring(6));
            Console.WriteLine(builder.Substring(6, 5));
            Console.WriteLine(builder.Substring(22));

            //Console.WriteLine(builder.Substring(20, 20));
            Console.WriteLine(builder.Substring(-1, 5));
        }
示例#17
0
        static void Main()
        {
            var sb = new StringBuilder();
            sb.Append("This is a test, not a text, but a test!");
            var ssb = sb.Substring(6, 10);
            Console.WriteLine(ssb);

            bool test1 = sb.Substring(2, 1).ToString().Equals("i"); // This is true.
            Console.WriteLine(test1);
        }
        static void Main()
        {
            StringBuilder testStrBuilder = new StringBuilder("hello I are baboon");

            var testOne = testStrBuilder.Substring(0, 5);
            Console.WriteLine("Taking the first five symbols: {0}", testOne.ToString());

            testOne = testStrBuilder.Substring(6);
            Console.WriteLine("Taking all symbols after the 6th: {0}", testOne);
        }
示例#19
0
        private static void Main()
        {
            Console.Write("Enter string for test: ");
            string input = Console.ReadLine();

            StringBuilder builder = new StringBuilder();
            builder.Append(input);
            Console.WriteLine(builder.Substring(1, 2));
            Console.WriteLine(builder.Substring(4));
        }
    static void Main()
    {
        StringBuilder test = new StringBuilder("This is a test string.");

        Console.WriteLine("The full string:");
        Console.WriteLine(test);
        Console.WriteLine("Called with start index 10:");
        Console.WriteLine(test.Substring(10));
        Console.WriteLine("Called with start index 10 and lenght 4:");
        Console.WriteLine(test.Substring(10, 4));
    }
        static void Main()
        {
            Console.WriteLine("Task 01 - StringBuilder Extension");
            StringBuilder txt = new StringBuilder("AlaBalaNitsa ili oshte po-smisleno - Shalalala (the last is copyright protected) ");
            Console.WriteLine("\r\nThe text: " + txt);
            Console.WriteLine("\r\nSubstring(38) = \"{0}\"", txt.Substring(37));
            Console.WriteLine("Substring(3,4) = \"{0}\"", txt.Substring(3,4));

            Console.WriteLine("\r\nPress Enter to finish");
            Console.ReadLine();
        }
        public void Substring()
        {
            // Type
            var @this = new StringBuilder("0123456789");

            // Exemples
            var result1 = @this.Substring(4); // return "456789"
            var result2 = @this.Substring(4, 2); // return "45"

            // Unit Test
            Assert.AreEqual("456789", result1);
            Assert.AreEqual("45", result2);
        }
示例#23
0
        static void Main()
        {
            StringBuilder test1 = new StringBuilder();
            test1.Append("hello I will try to remove the hello part");

            StringBuilder result1 = test1.Substring(6);
            StringBuilder result2 = test1.Substring(13, 14);

            Console.WriteLine(test1);
            Console.WriteLine(result1);
            Console.WriteLine(result2);
            Console.WriteLine();
        }
        public static void Main()
        {
            StringBuilder sb = new StringBuilder("asfsfdgd");
            Console.WriteLine(sb.Substring(5, 3));
            Console.WriteLine(sb.Substring(5, 5));

            sb.RemoveText("sf");
            Console.WriteLine(sb);

            List<int> numbers = new List<int>() { 1, 2, 3, 4, 5 };

            sb.AppendAll(numbers);
            Console.WriteLine(sb);
        }
示例#25
0
        static void Main()
        {
            //Try the Substring method on class String
            string newString = "Pesho Plet Plete";
            Console.WriteLine("Try the Substring method on class String:");
            Console.WriteLine(newString.Substring(2));
            Console.WriteLine(newString.Substring(2, 2));

            //Try the Substring method on class StringBuilder
            Console.WriteLine("\nTry the Substring method on class StringBuilder:");
            StringBuilder newStringBuilder = new StringBuilder("Pesho Plet Plete");
            Console.WriteLine(newStringBuilder.Substring(2));
            Console.WriteLine(newStringBuilder.Substring(2, 2));
        }
示例#26
0
 static void Main()
 {
     var sb = new StringBuilder();
     sb.Append("Keep calm and learn to code");
     sb = sb.Substring(0, 100);
     Console.WriteLine(sb);
 }
 public void SubstringUnitTest4()
 {
     StringBuilder sb = new StringBuilder("testing my extention.");
     StringBuilder result = sb.Substring(3, 3);
     Console.WriteLine(result);
     Assert.AreEqual("tin", result.ToString(), "Error in SubstringUnitTest4");
 }
 public void SubstringUnitTest3()
 {
     StringBuilder sb = new StringBuilder("testing my extention.");
     StringBuilder result = sb.Substring(0, 0);
     Console.WriteLine(result);
     Assert.AreEqual(string.Empty, result.ToString(), "Error in SubstringUnitTest3");
 }
示例#29
0
    static void Main()
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("trala lala");

        Console.WriteLine(sb.Substring(3,6));
    }
示例#30
0
 static void Main()
 {
     StringBuilder sb = new StringBuilder();
     sb.AppendLine("Az sum goshko velikiq !");
     string str = sb.Substring(0, 13);
     Console.WriteLine(str);
 }