Пример #1
0
        public static string EnumerableToString <T>(IEnumerable <T> enumerable, string separator)
        {
            if (enumerable == null)
            {
                return(String.Empty);
            }
            NullUtil.CheckForNull(separator, "separator");
            StringBuilder sb = new StringBuilder();

            foreach (T obj in enumerable)
            {
                if (obj != null)
                {
                    string str = obj.ToString();
                    if (StringUtil.IsNotNullOrWhitespace(str))
                    {
                        sb.Append(str);
                        sb.Append(separator);
                    }
                }
            }
            if (sb.Length != 0)
            {
                return(sb.Remove((sb.Length - separator.Length), separator.Length).ToString());
            }
            return(String.Empty);
        }
Пример #2
0
        public static string ReplaceFirst(this string value, string oldValue, string newValue, StringComparison comparison)
        {
            NullUtil.CheckForNull(oldValue, "oldValue");
            if (newValue == null)
            {
                newValue = String.Empty;
            }
            string str1 = value;

            if (StringUtil.IsNotNullOrWhitespace(value))
            {
                int len = value.IndexOf(oldValue, comparison);
                if ((0 <= len) && (len < value.Length))
                {
                    string str2 = String.Empty;
                    if (len > 0)
                    {
                        str2 = value.Substring(0, len);
                    }
                    string str3       = String.Empty;
                    int    startIndex = checked (len + oldValue.Length);
                    if (startIndex < value.Length)
                    {
                        str3 = value.Substring(startIndex);
                    }
                    str1 = (str2 + newValue + str3);
                }
            }
            return(str1);
        }
Пример #3
0
        public static string GetUrlDirectory(string url)
        {
            NullUtil.CheckForNull(url, "url");
            int len = url.IndexOf(CharUtil.QuestionMark);

            if (len >= 0)
            {
                url = url.Substring(0, len);
            }
            string dirName;
            string leafName;

            SplitUrl(url, out dirName, out leafName);
            return(dirName);
        }
Пример #4
0
        public static List <String> GetQueryStringKeys(Uri uri)
        {
            NullUtil.CheckForNull(uri, "uri");
            List <String> list  = new List <String>();
            string        query = uri.Query;

            if ((StringUtil.IsNotNullOrWhitespace(query)) && (query.Length > 1))
            {
                string             str     = query.Substring(1);
                StringSplitOptions options = StringSplitOptions.RemoveEmptyEntries;
                string             str2    = str;
                char[]             sep     = new char[1] {
                    CharUtil.Ampersand
                };
                int num = (int)options;
                foreach (string str3 in str2.Split(sep, options))
                {
                    list.Add(str3.Split(new char[1] {
                        CharUtil.EqualSign
                    }, options)[0]);
                }
            }
            return(list);
        }