namespace BlazorPages.Tools
{
    public static class UriExtenssions
    {
        public static string GetQueryStringValue(string uri, string key)
        {
            try
            {
                var parts = uri.Split("?", options: StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length != 2)
                    return "";
                var qparts = parts[1].Split("&");
                foreach (var kv in qparts)
                {
                    var k = kv.Split("=")[0];
                    var v = kv.Split("=")[1];
                    if (k.Equals(key, StringComparison.InvariantCultureIgnoreCase))
                        return v;
                }
                return "";
            }
            catch (Exception)
            {

                return "";
            }
        }
    }
}
