Hardly.StringHelpers.GetBefore C# (CSharp) Method

GetBefore() public static method

public static GetBefore ( this source, string searchToken, bool firstOrLastInstance = true ) : string
source this
searchToken string
firstOrLastInstance bool
return string
        public static string GetBefore(this string source, string searchToken, bool firstOrLastInstance = true)
        {
            if(source != null) {
                if(searchToken != null && searchToken.Length > 0) {
                    int i;
                    if(firstOrLastInstance) {
                        i = source.IndexOf(searchToken);
                    } else {
                        i = source.LastIndexOf(searchToken);
                    }
                    if(i >= 0) {
                        if(i < source.Length) {
                            return source.Substring(0, i);
                        }
                    }
                } else {
                    Debug.Fail();
                }
            }

            return null;
        }