C# 关于 &符号,字符串转字典Dictionary<string, string>

private static Dictionary<string, string> ParseToDictionary(string str)
        {
            Dictionary<string, string> result = new Dictionary<string, string>();

            var pairs = str.Split('&');
            foreach (var p in pairs)
            {
                var items = p.Split('=');
                if (items.Length == 2)
                {
                    result.Add(items[0], items[1]);
                }
                else
                    continue;
            }

            return result;
        }

 

posted @ 2021-05-08 10:38  LuoCore  阅读(882)  评论(0编辑  收藏  举报