Home > Software engineering >  All characters in the text digital Arabic numerals
All characters in the text digital Arabic numerals

Time:10-25

 Option Explicit 

The Function CNum (ByVal CdataStr As String) As String
Dim I As an Integer, independence Idx As an Integer, Idc As Integer
Dim TMP As String, sTmp As String, cTmp As String, aTmp As String
Dim Char, CharUnit, Num
Dim rmbFormat As String
Dim NumLong As Long
Dim NumTmp As Long, NumTmpA As Long, NumTmpB As Long

On Error GoTo errexit

'the ghost word list
Char=Array (" a ", "2", "three", "four", "five", "six", "seven", "eight" and "nine", "ten", "best", "qian")
'standard word list
CharUnit=Array (" zero ", "one", "two", "3", "the boss", "wu", "land", "pure", ""," nine ", "pick up", "hk", "$"," wan ", "$")
'Chinese digital list
Num=Array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

RmbFormat="pick up hk $company billion"

'unified capital standard
For I=0 To UBound (Char)
CdataStr=Replace (CdataStr, Char (I), CharUnit (I))
Next

'digital conversion for the Arabic numeral
For I=0 To UBound (Num)
CdataStr=Replace (CdataStr, CharUnit (I), Num (I))
Next

For I=1 To Len (CdataStr)
TMP=Mid (CdataStr, I, 1)

If IsNumeric (TMP) Then 'digital processing
NumTmp=Val (TMP)
If NumTmp=0 Then 'in the digits 0 processing
Independence Idx=independence Idx - 1
End the If
If I=Len (CdataStr) Then 'digital end processing
NumLong=NumLong + NumTmpB + NumTmp
CTmp=CStr (NumLong)
NumLong=0
NumTmpB=0
NumTmp=0
End the If
The Else 'Chinese character processing
Independence Idx=InStr (rmbFormat, TMP) 'figures read
If independence Idx & gt; 0 Then 'uppercase characters processing
If independence Idx & lt; Thousand digits=3 Then 'processing
If NumTmp & gt; 0 Then 'pick up hundred thousand "not empty"
NumTmpB=NumTmpB + NumTmp * 10 ^ independence Idx
NumTmp=0
Independence Idx=independence Idx - 1
The Else
If NumTmpB & gt; 0 Then 'pick BaiQian before "empty" prefix digital display Chinese characters, such as: 600000=600000
CTmp=CStr (NumTmpB) & amp; TMP
The Else
If independence Idx=1 Then 'no prefix number ten empty section: only ten=10
NumTmp=1
NumTmpB=NumTmp * 10 ^ independence Idx
NumTmp=0
Independence Idx=independence Idx - 1
The Else 'no numerical prefix empty words such as "best"="best"
CTmp=TMP
End the If
End the If
End the If
ElseIf independence Idx=0 Or independence Idx=4 Or 8 Then independence Idx='trillions of digits piecewise calculation, reservation vacancy number (independence Idx=0)
If NumTmp & gt; 0 Or NumTmpB & gt; 0 Then 'calculation only appears for the first time, the next time a suffix (such as: 100000 only calculate the first "m", the second "wan" as suffix)
NumLong=NumLong + 10 ^ (NumTmpB + NumTmp) * independence Idx 'keep this data, after the home run into the digital
NumTmpB=0
NumTmp=0
ElseIf NumLong & gt; 0 Then 'suffix processing of Chinese characters, such as: 100000 to calculate the first "m", the second "than" a suffix processing
CTmp=CStr (NumLong) & amp; TMP
NumLong=0
End the If
Idc independence Idx=1
ElseIf NumLong=0 And NumTmp=0 And NumTmpB & gt; 0 Then 'best pick suffix processing
CTmp=CStr (NumTmpB) & amp; TMP
NumTmpB=0
The Else
CTmp=TMP 'is greater than the "million" Chinese characters, Numbers and the capital - processing character directly displays such as: 100 million=100 million
Idc=0
End the If
The Else 'other Chinese character or character processing
If NumLong & gt; 0 Or NumTmp & gt; 0 Or NumTmpB & gt; 0 Then 'partial numerical characters merge
NumLong=NumLong + 10 ^ (NumTmpB + NumTmp) * independence Idx
CTmp=CStr (NumLong)
NumLong=0
NumTmp=0
NumTmpB=0
End the If

CTmp=cTmp & amp; TMP
End the If

If I=Len (CdataStr) And cTmp="" Then" the end of the conversion process, such as: 10000=100.0001 billion=1000000 to end the internal output end of the calculation results
If NumLong & gt; 0 Or NumTmpB & gt; 0 Or NumTmp & gt; 0 Then
NumLong=NumLong + 10 ^ (NumTmpB + NumTmp) * independence Idx
CTmp=CStr (NumLong)
NumTmp=0
NumLong=0
NumTmpB=0
The Else 'no internal digital calculation processing
CTmp=TMP
End the If
End the If
End the If


If cTmp & lt;> "" Then" convert data, character, string
STmp=sTmp & amp; CTmp
CTmp=""
End the If

Next I


'transformation is successful, the output dataCNum=sTmp
The Exit Function

'output conversion fails, empty
Errexit:
CNum=""
End the Function

Private Sub Form_Load ()
The Debug. Print CNum (" pick up ")
The Debug. Print CNum (" best ")
The Debug. Print CNum (" our ten ")
Debug. Print CNum (" amount: hexagon 0.1 billion is picked up three best 050000 yuan, up 20000 people ")
Debug. Print CNum (" micky one hk lu SAN she eight yuan and fifty cents a minute ")
The Debug. Print CNum (" ten thousand SAN she lu ")

The Debug. Print CNum (" five hundred million yuan every day ")
The Debug. Print CNum (" I want to pick up yuan ")
End Sub



Results:
10
Hk
Pick up 500
Amount: 1003050008 yuan 6 Angle, a population of 1.2 billion
$6138 1
10036
500000000 yuan every day
I want to 10 yuan

CodePudding user response:

One thousand I used thirty-one thousand to buy ten thousand macro electronics, I will send to families,

You to convert

CodePudding user response:

The
refer to the original poster u012140181 response:
result:
10
Hk
Pick up 500
Amount: 1003050008 yuan 6 Angle, a population of 1.2 billion
$6138 1
10036
500000000 yuan every day
I want to 10 yuan


 Private Sub Form_Load () 
Me. Show
Me. Print CNum (" pick up ")
Me. Print CNum (" best ")
Me. Print CNum (" our ten ")
Me. Print CNum (" amount: hexagon 0.1 billion is picked up three best 050000 yuan, up 20000 people ")
Me. Print CNum (" micky one hk lu SAN she eight yuan and fifty cents a minute ")
Me. Print CNum (" ten thousand SAN she lu ")

Me. Print CNum (" five hundred million yuan every day ")
Me. Print CNum (" I want to pick up yuan ")
End Sub

Slightly change the LZ Form_Load code, the output to the form, the results with the results of the LZ,

CodePudding user response:

Don't say the semantic analysis and participles, even without basic state machine can parse text program, simply don't have to see,

CodePudding user response:



The building Lord, your "results" is your "imagine the result of"!
Can't you see results?
(I think usually run to see! nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related