Substring

In this chapter you will learn:

  1. How to get the sub string from the start of a string
  2. How to get the sub string from the middle

Get the substring from the start of a string

SubString returns the substring from the current. Specify only the start position

using System;//from  ja  v  a  2  s  . c  om

class Sample
{
    public static void Main()
    {
        string s = "java2s.com";

        Console.WriteLine(s.Substring(2));
    }
}

The output:

Get the sub string from the middle

Specify both the start and end

using System;/*from j  av a  2s  .com*/

class Sample
{
    public static void Main()
    {

        string s = "java2s.com";

        Console.WriteLine(s.Substring(2, 3));
    }
}

The output:

Next chapter...

What you will learn in the next chapter:

  1. How to escape characters in String
  2. Character escape sequence: \0
  3. Escape sequences in strings: embed quotes
  4. Escape sequences in strings: \t (tab)
  5. Escape sequences in strings: \n (new line)
Home » C# Tutorial » String
string
String creation
Char in string
Compare strings
String equality
String concatanation
String copy
String Join
String split
String Search for Index
String contains
String start with
String insert
String case
Replacing substring
Remove from a string
Substring
Escape Characters
String verbatim
String padding
Switch on String
String trim
String intern
String normalization
Empty String