Dim ChineseAmount As String =args(0)
Dim numMap() As String = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"} '数字映射表
Dim unitMap() As String = {"分", "角", "元", "拾", "佰", "仟", "万", "亿"} '单位映射表
Dim unitValueMap() As Double = {0.01, 0.1, 1, 10, 100, 1000, 10000, 100000000} '单位值映射表
Dim sectionResult As Double
Dim result As Double
Dim currentNum As Double = 0
Dim currentUnit As Double = 0
Dim lenStr As Integer
ChineseAmount = ChineseAmount.Replace("圆","元")
lenStr = ChineseAmount.length
sectionResult = 0
result = 0
For i As Integer = 1 To lenStr
Dim currentChar As String
currentChar = ChineseAmount.Chars(i-1)
' 处理"整"字
If currentChar = "整" Then
Exit For
End If
' 检查是否为数字
Dim isNumber As Boolean = False
For numIndex As Integer = 0 To numMap.length -1
If currentChar = numMap(numIndex) Then
isNumber = True
currentNum = numIndex
Exit For
End If
Next
' Output.Show("i:="&i)
' Output.Show("当前字符"¤tChar)
' Output.Show("currentNum "¤tNum)
' Output.Show("numIndex"& numIndex)
If isNumber Then '如果是数字
' 是数字,继续处理下一个字符
Continue For
End If
' 检查是否为单位
Dim unitIndex As Integer
unitIndex = -1
For unitIndex = 0 To unitMap.length -1
If currentChar = unitMap(unitIndex) Then
currentUnit = unitValueMap(unitIndex)
If unitIndex = 6 Or unitIndex = 7 Then ' 万或亿
sectionResult = (sectionResult + currentNum) * currentUnit
result = result + sectionResult
sectionResult = 0
Else
sectionResult = sectionResult + currentNum * currentUnit
End If
currentNum = 0
Exit For
End If
Next
Next
result = result + sectionResult
Return result