Ejemplo n.º 1
0
        public static string LeftFromFirst(this StringExtensions.SubstrExtensionPoint sp, string substring, StringComparison comparison = StringComparison.Ordinal)
        {
            string extendedValue = sp.ExtendedValue;

            return(extendedValue.Safe <string, string>((string s) => {
                substring = substring.EmptyIfNull();
                int num = (s.IndexOf(substring, comparison) >= 0 ? s.IndexOf(substring, comparison) : -1);
                if (num < 0)
                {
                    return null;
                }
                return sp.Left(num);
            }, null));
        }
Ejemplo n.º 2
0
        public static string LeftFromLast(this StringExtensions.SubstrExtensionPoint sp, string substring, StringComparison comparison = StringComparison.Ordinal)
        {
            string extendedValue = sp.ExtendedValue;

            return(extendedValue.Safe <string, string>((string s) => {
                substring = substring.EmptyIfNull();
                int num = -1;
                if (substring.IsEmpty())
                {
                    num = 0;
                }
                else if (s.LastIndexOf(substring, comparison) >= 0)
                {
                    num = s.LastIndexOf(substring, comparison);
                }
                if (num < 0)
                {
                    return null;
                }
                return sp.Left(num);
            }, null));
        }