How to extract a string lies between two strings in C#.Net?

Following is the C# code that except three string parameters. First string is the sentence from which string will be extracted and other two parameters are the strings from between which the string will be extracted.

/// <summary>

/// This function extracts a string from a sentence lies between two strings

/// </summary>

/// <param name="Text">Sentence from which string will be extracted</param>

/// <param name="FirstString">

/// Starting string after which the result string will be extracted

// </param>

/// <param name="LastString">

/// Ending string before which the result string will be extracted

/// </param>

/// <returns>Final string extracted from the Text parameter</returns>

 

public string Between(string Text, string FirstString, string LastString)

{

    string STR = Text;

    string STRFirst = FirstString;

    string STRLast = LastString;

    string FinalString;

    string TempString;

 

    int Pos1 = STR.IndexOf(FirstString) + FirstString.Length;

    int Pos2 = STR.IndexOf(LastString);

    FinalString = STR.Substring(Pos1, Pos2 - Pos1);

    return FinalString;}