Tuesday, April 23, 2013

Get Values Between String And Tags C#

public string GetStringBetween(string src, string findfrom, string findto)
        {
            try
            {
                int sIndex = src.IndexOf(findfrom);
                int eIndex = src.IndexOf(findto, sIndex + findfrom.Length);
                if (sIndex < 0 || eIndex < 0) return "";
                string s = src.Substring(sIndex + findfrom.Length, eIndex - sIndex - findfrom.Length);
                return s;
            }
            catch { return ""; }
        }

Example
//stirng strText = "abcd";
//string Result = GetStringBetween(strText,"","");
//result variable show you between string ;
//output : abcd

No comments:

Post a Comment