将印地语编号转换为vb.net中的单词

时间:2021-06-15 21:10:13

i am trying to convert numbers to word for a hindi invoice . like - 50001 to पांच हजार एक

我正在尝试将数字转换为印地文发票的单词。喜欢 - 50001到पांचहजारएक

 Public Shared Function changeToWords(ByVal numb As [String]) As [String]
    Dim val As [String] = "", wholeNo As [String] = numb, points As [String] = "", andStr As [String] = "", pointStr As [String] = ""
    Dim endStr As [String] = ""
    Try
        Dim decimalPlace As Integer = numb.IndexOf(".")
        If decimalPlace > 0 Then
            wholeNo = numb.Substring(0, decimalPlace)
            points = numb.Substring(decimalPlace + 1)
            If Convert.ToInt32(points) > 0 Then
                andStr = "दशाम्लौ"
                ' just to separate whole numbers from points
                pointStr = translateCents(points)
            End If
        End If
        val = [String].Format("{0} {1}{2} {3}", translateWholeNumber(wholeNo).Trim(), andStr, pointStr, endStr)
    Catch


    End Try
    Return val
End Function
Private Shared Function translateWholeNumber(ByVal number As [String]) As [String]
    Dim word As String = ""
    Try
        Dim beginsZero As Boolean = False
        'tests for 0XX
        Dim isDone As Boolean = False
        'test if already translated
        Dim dblAmt As Double = (Convert.ToDouble(number))
        'if ((dblAmt > 0) && number.StartsWith("0"))
        If dblAmt > 0 Then
            'test for zero or digit zero in a nuemric
            beginsZero = number.StartsWith("0")

            Dim numDigits As Integer = number.Length
            Dim pos As Integer = 0
            'store digit grouping
            Dim place As [String] = ""
            'digit grouping name:hundres,thousand,etc...

            Select Case numDigits
                Case 1
                    'ones' range
                    word = ones(number)
                    isDone = True
                    Exit Select
                Case 2
                    'tens' range
                    word = tens(number)
                    isDone = True
                    Exit Select
                Case 3
                    'hundreds' range
                    pos = (numDigits Mod 3) + 1
                    place = " सौ "
                    Exit Select
                    'thousands' range
                Case 4, 5
                    pos = (numDigits Mod 4) + 1
                    place = " हजार "
                    Exit Select

                Case 6, 7
                    pos = (numDigits Mod 6) + 1
                    place = " लाख "
                    Exit Select
                    'millions' range
                Case 8, 9, 10
                    pos = (numDigits Mod 8) + 1
                    place = " करोड़ "
                    Exit Select

                Case Else
                    'add extra case options for anything above Billion...
                    isDone = True
                    Exit Select
            End Select
            If Not isDone Then
                'if transalation is not done, continue...(Recursion comes in now!!)
                word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos))
                'check for trailing zeros
                If beginsZero Then
                    word = " " & word.Trim()
                End If
            End If
            'ignore digit grouping names
            If word.Trim().Equals(place.Trim()) Then
                word = ""
            End If
        End If
    Catch


    End Try
    Return word.Trim()
End Function
Private Shared Function tens(ByVal digit As [String]) As [String]
    Dim digt As Integer = Convert.ToInt32(digit)
    Dim name As [String] = Nothing
    Select Case digt
        Case 10
            name = "दस"
            Exit Select
        Case 11
            name = "ग्यारह"
            Exit Select
        Case 12
            name = "बारह"
            Exit Select
        Case 13
            name = "तेरह"
            Exit Select
        Case 14
            name = "चौदह"
            Exit Select
        Case 15
            name = "पंद्रह"
            Exit Select
        Case 16
            name = "सोलह"
            Exit Select
        Case 17
            name = "सतरह"
            Exit Select
        Case 18
            name = "अट्ठारह"
            Exit Select
        Case 19
            name = "उन्नीस"
            Exit Select
        Case 20
            name = "बीस"
            Exit Select
        Case 21
            name = "इक्कीस"
            Exit Select
        Case 22
            name = "बाईस"
            Exit Select
        Case 23
            name = "तेईस"
            Exit Select
        Case 24
            name = "चौबीस"
            Exit Select
        Case 25
            name = "पच्चीस"
            Exit Select
        Case 26
            name = "छब्बीस"
            Exit Select
        Case 27
            name = "सत्ताईस"
            Exit Select

        Case 28
            name = "अट्ठाईस"
            Exit Select

        Case 29
            name = "उनतीस"
            Exit Select
        Case 30
            name = "तीस"
            Exit Select
        Case 31
            name = "इकतीस"
            Exit Select
        Case 32
            name = "बत्तीस"
            Exit Select
        Case 33
            name = "तैंतीस"
            Exit Select
        Case 34
            name = "चौंतीस"
            Exit Select
        Case 35
            name = "पैंतीस"
            Exit Select
        Case 36
            name = "छ्त्तीस"
            Exit Select
        Case 37
            name = "सैंतीस"
            Exit Select
        Case 38
            name = "अड़तीस"
            Exit Select
        Case 39
            name = "उनतालीस"
            Exit Select
        Case 40
            name = "चालीस"
            Exit Select
        Case 41
            name = "इकतालीस"
            Exit Select
        Case 42
            name = "बयालीस"
            Exit Select
        Case 43
            name = "तैंतालीस"
            Exit Select
        Case 44
            name = "चौंतालीस"
            Exit Select
        Case 45
            name = "पैंतालीस"
            Exit Select
        Case 46
            name = "छियालीस"
            Exit Select
        Case 47
            name = "सैंतालीस"
            Exit Select
        Case 48
            name = "अड़तालीस"
            Exit Select
        Case 49
            name = "उनचास"
            Exit Select
        Case 50
            name = "पचास"
            Exit Select
        Case 51
            name = "इक्याबन"
            Exit Select
        Case 52
            name = "बावन"
            Exit Select
        Case 53
            name = "तिरेपन"
            Exit Select
        Case 54
            name = "चौबन"
            Exit Select
        Case 55
            name = "पचपन"
            Exit Select
        Case 56
            name = "छप्पन"
            Exit Select
        Case 57
            name = "सत्तावन"
            Exit Select
        Case 58
            name = "अट्ठावन"
            Exit Select
        Case 59
            name = "उनसठ"
            Exit Select
        Case 60
            name = "साठ"
            Exit Select
        Case 61
            name = "इकसठ"
            Exit Select
        Case 62
            name = "बासठ"
            Exit Select
        Case 63
            name = "तिरसठ"
            Exit Select
        Case 64
            name = "चौंसठ"
            Exit Select
        Case 65
            name = "पैंसठ"
            Exit Select
        Case 66
            name = "छियासठ"
            Exit Select
        Case 67
            name = "सड़सठ"
            Exit Select
        Case 68
            name = "अड़सठ"
            Exit Select
        Case 69
            name = "उनहत्तर"
            Exit Select
        Case 70
            name = "सत्तर"
            Exit Select
        Case 71
            name = "इकहत्तर"
            Exit Select
        Case 72
            name = "बहत्तर"
            Exit Select
        Case 73
            name = "तिहत्तर"
            Exit Select
        Case 74
            name = "चौहत्तर"
            Exit Select
        Case 75
            name = "पचहत्तर"
            Exit Select
        Case 76
            name = "छिहत्तर"
            Exit Select
        Case 77
            name = "सतहत्तर"
            Exit Select
        Case 78
            name = "अठहत्तर"
            Exit Select
        Case 79
            name = "उनासी"
            Exit Select
        Case 80
            name = "अस्सी"
            Exit Select
        Case 81
            name = "इक्यासी"
            Exit Select
        Case 82
            name = "बयासी"
            Exit Select
        Case 83
            name = "तिरासी"
            Exit Select
        Case 84
            name = "चौरासी"
            Exit Select
        Case 85
            name = "पचासी"
            Exit Select
        Case 86
            name = "छियासी"
            Exit Select
        Case 87
            name = "सतासी"
            Exit Select
        Case 88
            name = "अठासी"
            Exit Select
        Case 89
            name = "नवासी"
            Exit Select
        Case 90
            name = "नब्बे"
            Exit Select
        Case 91
            name = "इक्यानवे"
            Exit Select
        Case 92
            name = "बानवे"
            Exit Select
        Case 93
            name = "तिरानवे"
            Exit Select
        Case 94
            name = "चौरानवे"
            Exit Select
        Case 95
            name = "पचानवे"
            Exit Select
        Case 96
            name = "छियानवे"
            Exit Select
        Case 97
            name = "सत्तानवे"
            Exit Select
        Case 98
            name = "अट्ठानवे"
            Exit Select
        Case 99
            name = "निन्यानवे"
            Exit Select
        Case Else
            If digt > 0 Then
                name = (tens(digit.Substring(0, 1) & "0") & " ") + ones(digit.Substring(1))
            End If
            Exit Select
    End Select
    Return name
End Function
Private Shared Function ones(ByVal digit As [String]) As [String]
    Dim digt As Integer = Convert.ToInt32(digit)
    Dim name As [String] = ""
    Select Case digt
        Case 1
            name = "एक"
            Exit Select
        Case 2
            name = "दो"
            Exit Select
        Case 3
            name = "तीन"
            Exit Select
        Case 4
            name = "चार"
            Exit Select
        Case 5
            name = "पांच"
            Exit Select
        Case 6
            name = "छः"
            Exit Select
        Case 7
            name = "सात"
            Exit Select
        Case 8
            name = "आठ"
            Exit Select
        Case 9
            name = "नौ"
            Exit Select
    End Select
    Return name
End Function
Private Shared Function translateCents(ByVal cents As [String]) As [String]
    Dim cts As [String] = "", digit As [String] = "", engOne As [String] = ""
    For i As Integer = 0 To cents.Length - 1
        digit = cents(i).ToString()
        If digit.Equals("0") Then
            engOne = "शून्य"
        Else
            engOne = ones(digit)
        End If
        cts += " " & engOne
    Next
    Return cts
End Function

i tried the above coe . it is running but when the number comes like 50001 it gives output पचास हजार सौ एक . i want to write this as पचास हजार एक .

我尝试了以上的系数。它正在运行,但是当数字变为50001时,它会输出结果पचासहजारसौौक。我想把它写成पचासहजारएक。

1 个解决方案

#1


This modification seems to be working for me:

这个修改似乎对我有用:

'if transalation is not done, continue...(Recursion comes in now!!)
If (number.Substring(0, 1) = "0") Then
    word = translateWholeNumber(number.Substring(pos))
Else
    word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos))
End If

Edit: Doing this breaks output if the original string sent to changeToWords begins with any zeros. To rectify that condition, you can trim leading zeros, before the string is processed:

编辑:如果发送到changeToWords的原始字符串以任何零开头,则执行此操作会中断输出。要纠正这种情况,您可以在处理字符串之前修剪前导零:

wholeNo As [String] = numb.TrimStart("0"c)

#1


This modification seems to be working for me:

这个修改似乎对我有用:

'if transalation is not done, continue...(Recursion comes in now!!)
If (number.Substring(0, 1) = "0") Then
    word = translateWholeNumber(number.Substring(pos))
Else
    word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos))
End If

Edit: Doing this breaks output if the original string sent to changeToWords begins with any zeros. To rectify that condition, you can trim leading zeros, before the string is processed:

编辑:如果发送到changeToWords的原始字符串以任何零开头,则执行此操作会中断输出。要纠正这种情况,您可以在处理字符串之前修剪前导零:

wholeNo As [String] = numb.TrimStart("0"c)