Roman To Numbers

This algorithm converts roman numerals to decimal numbers.



									Private Enum RomanDigit
	I = 1
	V = 5
	X = 10
	L = 50
	C = 100
	D = 500
	M = 1000
End Enum

Public Shared Function RomanToNumbers(roman As String) As Integer
	roman = roman.ToUpper().Trim()
	If roman = "N" Then
		Return 0
	End If

	Dim ptr As Integer = 0
	Dim values As New ArrayList()
	Dim maxDigit As Integer = 1000
	While ptr < roman.Length
		Dim numeral As Char = roman(ptr)
		Dim digit As Integer = CInt([Enum].Parse(GetType(RomanDigit), numeral.ToString()))

		Dim nextDigit As Integer = 0
		If ptr < roman.Length - 1 Then
			Dim nextNumeral As Char = roman(ptr + 1)
			nextDigit = CInt([Enum].Parse(GetType(RomanDigit), nextNumeral.ToString()))

			If nextDigit > digit Then
				maxDigit = digit - 1
				digit = nextDigit - digit
				ptr += 1
			End If
		End If

		values.Add(digit)
		ptr += 1
	End While

	Dim total As Integer = 0
	For Each digit As Integer In values
		total += digit
	Next

	Return total
End Function
								


Example

									Dim data = "CDXIX"
Dim value = RomanToNumbers(data)
								


Output

									419