Esempio n. 1
0
        public static string Right(this StringExtensions.SubstrExtensionPoint ep, int length)
        {
            int    num           = length;
            string extendedValue = ep.ExtendedValue;

            num = Math.Max(num, 0);
            return(extendedValue.Safe <string, string>((string s) => {
                if (s.Length <= num)
                {
                    return s;
                }
                return s.Substring(s.Length - num, num);
            }, null));
        }
Esempio n. 2
0
        public static string RightFromFirst(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) + substring.Length : -1);
                if (num < 0)
                {
                    return null;
                }
                return sp.Right(s.Length - num);
            }, null));
        }
Esempio n. 3
0
        public static string RightFromLast(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 length = -1;
                if (substring.IsEmpty())
                {
                    length = s.Length;
                }
                else if (s.LastIndexOf(substring, comparison) >= 0)
                {
                    length = s.LastIndexOf(substring, comparison) + substring.Length;
                }
                if (length < 0)
                {
                    return null;
                }
                return sp.Right(s.Length - length);
            }, null));
        }
Esempio n. 4
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));
        }