1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| Private Function ConversionHelper(ByVal digit As Integer, ByVal position As Integer) As String
Dim retVal As New System.Text.StringBuilder()
Dim romanLetterList As New List(Of Char())
romanLetterList.Add(New Char() {"I"c, "V"c}) '1, 5
romanLetterList.Add(New Char() {"X"c, "L"c}) '10, 50
romanLetterList.Add(New Char() {"C"c, "D"c}) '100, 500
romanLetterList.Add(New Char() {"M"c, "?"c}) '1000, ? (No char symbol for 5000)
If position = 4 Then
retVal.Append(romanLetterList(position - 1)(0), digit)
Else
Select Case digit
Case 0 To 3
retVal.Append(romanLetterList(position - 1)(0), digit)
Case 4
retVal.Append(romanLetterList(position - 1)(0), 1)
retVal.Append(romanLetterList(position - 1)(1), 1)
Case 5
retVal.Append(romanLetterList(position - 1)(1), 1)
Case 6 To 8
retVal.Append(romanLetterList(position - 1)(1), 1)
retVal.Append(romanLetterList(position - 1)(0), digit - 5)
Case 9
retVal.Append(romanLetterList(position - 1)(0), 1)
retVal.Append(romanLetterList(position)(0), 1)
End Select
End If
Return retVal.ToString()
End Function
|
沒有留言:
張貼留言