Ejemplo n.º 1
0
        public static NameValueCollection ParseDelimited(string delimited)
        {
            var nvc = new NameValueCollection();

            if (delimited == null)
            {
                return(nvc);
            }

            foreach (var pair in delimited.Split('&'))
            {
                var kvp = pair.Split(new[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                if (kvp.Length == 0)
                {
                    continue;
                }

                string key = kvp[0].Trim();
                if (String.IsNullOrEmpty(key))
                {
                    continue;
                }
                string value = kvp.Length > 1 ? kvp[1].Trim() : null;
                nvc[key] = UrlDecoder.UrlDecode(value);
            }

            return(nvc);
        }
Ejemplo n.º 2
0
        internal static IEnumerable <KeyValuePair <string, string> > ParseToEnumerable(string value, char[] delimiters = null)
        {
            value      = value ?? String.Empty;
            delimiters = delimiters ?? DefaultParamSeparators;

            var items = value.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

            foreach (var item in items)
            {
                string[] pair = item.Split(ParamKeyValueSeparator, 2, StringSplitOptions.None);

                string pairKey   = UrlDecoder.UrlDecode(pair[0]).TrimStart(LeadingWhitespaceChars);
                string pairValue = pair.Length < 2 ? String.Empty : UrlDecoder.UrlDecode(pair[1]);

                yield return(new KeyValuePair <string, string>(pairKey, pairValue));
            }
        }