There is a similar question in here. In that question X happens to be ( and Y happened to be ). I am looking for something like
public string GetStringBetweenStrings(string Source, string leftString, string rightString)
{
// implementation
Return middlePart;
}
So that when I call that method as:
var test = GetStringBetweenStrings("Hello World this is a test","World","test");
// then test = " this is a ";
how can I build that function
In the same linked question, you have a more flexible answer that works for all strings, modified here:
This assumes that both strings are contained in the source string. What behaviour do you want if either one isn’t? Or if start is after end?
Obligatory regex version as per @Jack but updated into function: