works the same way as the default Substring, but it takes Start and End (exclusive) parameters instead of Start and Length - CSharp System

CSharp examples for System:String SubString

Description

works the same way as the default Substring, but it takes Start and End (exclusive) parameters instead of Start and Length

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Globalization;
using System.Collections.Generic;
using System;/*  w  w w.  j  a  va 2s.  c  om*/

public class Main{
        //Function that works the same way as the default Substring, but
        //it takes Start and End (exclusive) parameters instead of Start and Length
        //hello, 1, 3 -> el
        public static string SubstringEnd(string input, int start, int end)
        {
            if (start > end) //Flip the values
            {
                start ^= end;
                end = start ^ end;
                start ^= end;
            }

            if (end > input.Length) end = input.Length; //avoid errors

            return input.Substring(start, end - start);

        }
}

Related Tutorials