I have a string and index in that string, and want to get the first position of a substring before that index.
e.g., in string:
\"this is a test string tha
I know I am late to the party but this is the solution that I am using:
public static int FindIndexBefore(this string text, int startIndex, string searchString)
{
for (int index = startIndex; index >= 0; index--)
{
if (text.Substring(index, searchString.Length) == searchString)
{
return index;
}
}
return -1;
}
I tested it on your example and it gave the expected results.