GetStringBetween - Given a source string, it reads between two separate strings.
Ex. If Source String = "The Cat Ran", GetStringBetween(Source, "The ", " Ran) would return "Cat"
GetStringAfter - Given a source string, returns everything after the first instance of a string
Ex. If Source String = "The Cat Ran", GetStringAfter(Source, "The ") would return "Cat Ran"
Code:
private static string GetStringAfter(string src, string start) { int lnStart; string ret = ""; if (src.Contains(start)) { lnStart = src.IndexOf(start, 1) + start.Length; if(lnStart != -1) ret = src.Substring(lnStart + 1, src.Length-lnStart-1); } return ret; }
private static string GetStringBetween(string src, string start, string end) { int lnStart, lnEnd; string ret = ""; if (src.Contains(start) && src.Contains(end)) { lnStart = src.IndexOf(start, 1) + start.Length; lnEnd = src.IndexOf(end); if(lnStart != -1 && lnEnd != -1) ret = src.Substring(lnStart + 1, lnEnd - lnStart - 1); } return ret; }
0 comments:
Post a Comment