Demonstrating the string Substring method. - CSharp Language Basics

CSharp examples for Language Basics:string

Description

Demonstrating the string Substring method.

Demo Code



using System;// w  ww  .j  ava 2  s.co  m

class SubString
{
   static void Main()
   {
      var letters = "abcdefghijklmabcdefghijklm";

      // invoke Substring method and pass it one parameter
      Console.WriteLine("Substring from index 20 to end is " + $"\"{letters.Substring(20)}\"");

      // invoke Substring method and pass it two parameters
      Console.WriteLine("Substring from index 0 of length 6 is " + $"\"{letters.Substring(0, 6)}\"");
   }
}

Result


Related Tutorials