Skip to content

Instantly share code, notes, and snippets.

@AnthonyCarl
Created November 4, 2017 00:34
Show Gist options
  • Save AnthonyCarl/b81cee9a21f8e8fb32bf8e8704821ba7 to your computer and use it in GitHub Desktop.
Save AnthonyCarl/b81cee9a21f8e8fb32bf8e8704821ba7 to your computer and use it in GitHub Desktop.
UAParser Test
using System.Linq;
using System;
using UAParser;
string uaString = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Edge/15.15063";
// get a parser with the embedded regex patterns
var uaParser = Parser.GetDefault();
// get a parser using externally supplied yaml definitions
// var uaParser = Parser.FromYamlFile(pathToYamlFile);
// var uaParser = Parser.FromYaml(yamlString);
ClientInfo c = uaParser.Parse(uaString);
Console.WriteLine(c.UserAgent.Family); // => "Mobile Safari"
Console.WriteLine(c.UserAgent.Major); // => "5"
Console.WriteLine(c.UserAgent.Minor); // => "1"
Console.WriteLine(c.OS.Family); // => "iOS"
Console.WriteLine(c.OS.Major); // => "5"
Console.WriteLine(c.OS.Minor); // => "1"
Console.WriteLine(c.Device.Family); // => "iPhone"
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="UAParser" version="3.0.0" targetFramework="net45" />
</packages>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment