how to get string between two strings in c#

how to get string between two strings in c#

Example:

    string source="one two three four five"

   If you want to get strins between "one" and "five" then use this function call

   string temp = GetStringBetween("one ", "five", source);

And the copy the following function & paste in your program.

 public static string GetStringBetween(string strbegin, string strend, string source)
        {
            int iIndexOfBegin = source.IndexOf(strbegin) + strbegin.Length;
            string s1 = source.Substring(iIndexOfBegin);
            int iIndexOFfEnd = s1.IndexOf(strend);
            string s2 = s1.Substring(0, iIndexOFfEnd);
            return s2;
        }

Output:

"two three four"

Comments

Popular posts from this blog

Upload Single/Multiple file by using the REST API and jQuery SharePoint 2013

A type named 'SP.Data. could not be resolved by the model error

Add content type to SharePoint List/Library using REST API