Question: In data sometimes the same product will be named with a roman numeral while other times it will be a digit.

**Example** `Samsung Galaxy SII` verses `Samsung Galaxy S2`

How can the `II` be converted to the value `2`?

Answer: 
FWIW, here is a "try parse" version of David DeMar's answer:

```
private static readonly Dictionary<char, int> _romanMap = new Dictionary<char, int>() { { 'I', 1 }, { 'V', 5 }, { 'X', 10 }, { 'L', 50 }, { 'C', 100 }, { 'D', 500 }, { 'M', 1000 } };

public static bool TryParseRoman(string text, out int value)
{
    value = 0;
    if (string.IsNullOrEmpty(text))
        return false;

    var number = 0;
    for (var i = 0; i < text.Length; i++)
    {
        if (!_romanMap.TryGetValue(text[i], out var num))
            return false;

        if ((i + 1) < text.Length)
        {
            if (!_romanMap.TryGetValue(text[i + 1], out var num2))
                return false;

            if (num < num2)
            {
                number -= num;
                continue;
            }
        }

        number += num;
    }

    value = number;
    return true;
}

```
```
public int RomanToInt(string s)
{
    char[] romans = { 'I', 'V', 'X', 'L', 'C', 'D', 'M' };
    int[] nums = { 1, 5, 10, 50, 100, 500, 1000 };

    int result = 0;

    foreach (char c in s)
    {
        for (int i = 0; i < romans.Length; i++)
        {
            if (romans[i] == c)
            {
                result += nums[i];
            }
        }
    }

    if (s.Contains("IV") || s.Contains("IX"))
        result -= 2;

    if (s.Contains("XL") || s.Contains("XC"))
        result -= 20;

    if (s.Contains("CD") || s.Contains("CM"))
        result -= 200;

    return result;
}

```