cut string asp net code example

Example 1: c sharp substring

// To get a substring of a string use 'Substring()'
// The first value is the index of where to start and the second
// value is the lenght of the substring.
string str = "Hello World!"
str.Substring(3, 4) // Output: "lo W"
  
// If you only give a starting index, it will go until the end
str.Substring(3) // Output: "lo World!"

Example 2: C# copy string except for last letter

using System;

class Program
{
    static void Main()
    {
        string input = "OneTwoThree";

        string sub = input.Substring(0, input.Length - 5);
        Console.WriteLine("Substring: {0}", sub);
    }
}

Output

Substring: OneTwo