Archive for C#
Find a String Between 2 Strings
Posted by: | CommentsHere’s a way to return a substring of string that is between 2 strings in C#. There are other options for doing this, such as RegEx, but this is clean and simple.
// This search returns the substring between two strings, so // the first index is moved to the character just after the first string. int first = str.IndexOf("$string1$") + "$string1$".Length; int last = str.LastIndexOf("$string2$"); string str2 = str.Substring(first, last - first);

