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: 
```
/*
this uses the string object Replace() & Split() methods
*/
int ToNumber(string roman){
    /*
    the 0 padding after the comma delimiter allows adding up the extra index produced by Split, which is not numerical
    */
    string s1=roman.Replace("CM","900,0");
    s1=s1.Replace("M","1000,0");
    s1=s1.Replace("CD","400,0");
    s1=s1.Replace("D","500,0");
    s1=s1.Replace("XC","90,0");
    s1=s1.Replace("C","100,0");
    s1=s1.Replace("XL","40,0");
    s1=s1.Replace("L","50,0");
    s1=s1.Replace("IX","9,0");
    s1=s1.Replace("X","10,0");
    s1=s1.Replace("IV","4,0");
    s1=s1.Replace("V","5,0");
    s1=s1.Replace("I","1,0");

    string[] spl=s1.Split(",");
    int rlt=0;
    for(int i=0;i<spl.Count();i++)
    {
        rlt+= Convert.ToInt32(spl[i].ToString());
    }               
    return rlt;
}

```
```
public static int ConvertRomanNumtoInt(string strRomanValue)
{
    Dictionary RomanNumbers = new Dictionary
    {
        {"M", 1000},
        {"CM", 900},
        {"D", 500},
        {"CD", 400},
        {"C", 100},
        {"XC", 90},
        {"L", 50},
        {"XL", 40},
        {"X", 10},
        {"IX", 9},
        {"V", 5},
        {"IV", 4},
        {"I", 1}
    };
    int retVal = 0;
    foreach (KeyValuePair pair in RomanNumbers)
    {
        while (strRomanValue.IndexOf(pair.Key.ToString()) == 0)
        {
            retVal += int.Parse(pair.Value.ToString());
            strRomanValue = strRomanValue.Substring(pair.Key.ToString().Length);
        }
    }
    return retVal;
}

```