Jump to content
TrashBoat

Reverse _NumberNumToName

Recommended Posts

TrashBoat

This udf right here converts 700 into Seven Hundred, is there a way to reverse it so it would do from text into numbers?

Share this post


Link to post
Share on other sites
Deye

you need to download the above and keep it in same directory together with the UDF found in the link you posted

make sure you have included both udfs with your script testing  form i.e (#include <BigNum.au3> ) same for the other ..

Usage example: MsgBox(262144, "Test", _NumberNumToName(770))

Share this post


Link to post
Share on other sites
TrashBoat
Posted (edited)

thats not what i asked for ...

i know what that udf does but i need it do it backwards from  SEVEN HUNDRED SEVENTY to 770

Edited by Melba23
Quote deleted

Share this post


Link to post
Share on other sites
Deye
Posted (edited)

just to get you going, here is some quick sketch i came up with
note that its not clean nor fully tested ..

Edit: cleaned up a little more, let me know if some number fails to translate

MsgBox(0, "", NameToNumber("two hundred thousand thirty six"))

Func NameToNumber($Number)
    Local $iString, $Num = StringSplit($Number, " ", 1), $aArray[4][10] = _
            [ _
            ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'], _
            ['', '', 'hundred', 'thousand', '', '', '', '', '', ''], _
            ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'], _
            ['', 'One', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] _
            ]
    For $i = $Num[0] To 1 Step -1
        For $a = 0 To 3
            For $b = 0 To 9
                If $Num[$i] = $aArray[$a][$b] Then
                    Switch $a
                        Case 3
                            $iString = $b & $iString
                        Case 2
                            If StringLen($iString) = 1 Then
                                $iString = $b & $iString
                            Else
                                $iString = $b & 0 & $iString
                            EndIf
                        Case 1
                            If $b - StringLen($iString) < 0 Then
                                For $k = 1 To $b
                                    $iString = 0 & $iString
                                Next
                            Else
                                For $k = 1 To $b - StringLen($iString)
                                    $iString = 0 & $iString
                                Next
                            EndIf
                        Case 0
                            If $b = 0 Then
                                $iString = 10 & $iString
                            Else
                                $iString = 1 & $b & $iString
                            EndIf
                    EndSwitch
                    ExitLoop 2
                EndIf
            Next
        Next
    Next
    Return $iString
EndFunc   ;==>NameToNumber

 

Edited by Deye

Share this post


Link to post
Share on other sites
TrashBoat
Posted (edited)

Thanks for the reply ill try it!

Edited by Melba23
Quote deleted

Share this post


Link to post
Share on other sites
Melba23

TrashBoat,

When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - responders know what they wrote and it just pads the thread unnecessarily. Thanks for your cooperation.

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Deye

Updated the above code, let me know if some number still fails to translate ..

Share this post


Link to post
Share on other sites
TrashBoat
Posted (edited)

@Deye It loops through every each member in the array to check if it matches right? so if i would add a case 4 for thousands how would that work?

MsgBox(0, '', NameToNumber("one thousand seven hundred ninety three"))

Func NameToNumber($Number)
    Local $aArray[5][10] = _
            [ _
            ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'], _
            ['', 'hundred', 'two hundred', 'three hundred', 'four hundred', 'five hundred', 'six hundred', 'seven hundred', 'eight hundred', 'nine hundred'], _
            ['', '', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'], _
            ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'], _
            ['one thousand', 'two thousand', 'three thousand', 'four thousand', 'five thousand', 'six thousand', 'seven thousand', 'eight thousand', 'nine thousand','ten thousand'] _
            ]

    $Num = StringSplit($Number, " ", 1)

    Local $iString

    For $i = $Num[0] To 1 Step -1
        For $a = 0 To 4
            For $b = 0 To 9
                If $Num[$i] = $aArray[$a][$b] Then
                    Switch $a
                        Case 4
                            If StringLen($iString) >= 2 Then
                            ElseIf StringLen($iString) >= 1 Then
                                $iString = 0 & 0 & $iString
                            Else
                                $iString = 0 & 0 & 0 & $iString
                            EndIf
                        Case 3
                            $iString = "," & $b & $iString
                        Case 2
                            If StringInStr($iString, ",") Then
                                If StringLen($iString) >= 1 Then
                                    $iString = $b & $iString
                                EndIf
                            Else
                                $iString = $b & 0 & 0 & $iString
                            EndIf
                        Case 1
                            If StringLen($iString) >= 2 Then
                            ElseIf StringLen($iString) >= 1 Then
                                $iString = 0 & $iString
                            Else
                                $iString = 0 & 0 & $iString
                            EndIf
                        Case 0
                            If StringInStr($iString, ",") Then
                                If $b = 0 Then
                                    $iString = 10 & $iString
                                Else
                                    $iString = 1 & $b & $iString
                                EndIf
                            Else
                                If $b = 0 Then
                                    $iString = 10 & $iString
                                Else
                                    $iString = 1 & $b & $iString
                                EndIf
                            EndIf
                    EndSwitch
                    ExitLoop 2
                EndIf
            Next
        Next
    Next
    Return StringReplace($iString, ",", "")
;~ Return $iString
EndFunc   ;==>NameToNumber

Edit: I added the thousands part to the array and took your case 1 because that's where it loops through hundreds so it should be the same with thousands and i added a extra zero in case 4 it seems to work so far

Edited by TrashBoat

Share this post


Link to post
Share on other sites
Deye

Please try the above edited code, changed for adding in the thousands .. if it all worked well then we got it .. :D

Share this post


Link to post
Share on other sites
Melba23
Posted (edited)

Hi,

A fun little challenge for a windy afternoon. Here is my suggestion:

#include <StringConstants.au3>

Local $aMajorDivisions[3] = ["billion", "million", "thousand"]

Local $aDecades[10] = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
Local $aTens[10] = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
Local $aUnits[10] = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]

; ###########################

; Example

Local $aInitialAmounts[] = ["One hundred and three billion five hundred and eleven million two hundred and thirteen thousand seven hundred and fifty five", _
                            "One hundred and three billion two hundred and thirteen thousand seven hundred and fifty five", _
                            "One hundred and three billion eleven million nineteen thousand and one", _
                            "Five hundred and thirteen thousand seven hundred and fifty five", _
                            "Five hundred and thirteen thousand"]

For $n = 0 To UBound($aInitialAmounts) - 1
    $sRet = _NumberStringToDigits($aInitialAmounts[$n])
    ConsoleWrite($aInitialAmounts[$n] & @CRLF & $sRet & @CRLF)
Next

; ###########################

Func _NumberStringToDigits($sInitialAmount)

    ; Remove any English "and"s
    $sWorkingAmount = StringReplace($sInitialAmount, " and ", " ")
    ; Initialise return
    $sFigures = ""

    For $i = 0 To 2
        ; Look for major division (billion, million, thousand)
        $iPos = StringInStr($sWorkingAmount, $aMajorDivisions[$i])
        If $iPos Then
            ; Get value of major division
            $sValue = StringMid($sWorkingAmount, 1, $iPos - 1)
            ; And parse it
            $sFigures &= _ParseHundred($sValue) & ","
            ; Strip to next division
            $sWorkingAmount = StringTrimLeft($sWorkingAmount, $iPos + StringLen($aMajorDivisions[$i]))
        Else
            ; No major division
            If $sFigures Then
                $sFigures &= "000,"
            EndIf
        EndIf
    Next
    ; Parse any remaining hundred value
    If $sWorkingAmount Then
        $sFigures &= _ParseHundred($sWorkingAmount)
    Else
        $sFigures &= "000"
    EndIf

    ; Strip any leading zeroes
    While StringLeft($sFigures, 1) = 0
        $sFigures = StringTrimLeft($sFigures, 1)
    WEnd

    Return $sFigures

EndFunc   ;==>_NumberStringToDigits

Func _ParseHundred($sMajorValue)

    ; Initialise return
    $sIntFigures = ""
    ; Initialise unit value
    $sUnits = ""

    ; Look for "hundred"
    $aSplit = StringSplit($sMajorValue, "hundred", $STR_ENTIRESPLIT)
    If @error Then
        ; Add "0" if no hundred
        $sIntFigures &= "0"
        ; Set unit value
        $sUnits = $sMajorValue
    Else
        ; Parse hundred value
        For $j = 1 To 9
            If StringInStr($aSplit[1], $aUnits[$j]) Then
                ; Add hundred value
                $sIntFigures &= $j
                ; Set unit value
                $sUnits = $aSplit[2]
                ExitLoop
            EndIf
        Next
    EndIf

    ; Parse unit value
    ; Look for 10-19
    For $j = 0 To 9
        If StringInStr($sUnits, $aTens[$j]) Then
            ; Add value
            $sIntFigures &= "1" & $j
            ExitLoop
        EndIf
    Next
    ; If not found then look for decades
    If $j > 9 Then
        For $j = 2 To 9
            If StringInStr($sUnits, $aDecades[$j]) Then
                ; Add value
                $sIntFigures &= $j
                ExitLoop
            EndIf
        Next
        If $j > 9 Then
            ; Add "0"  if no ten value
            $sIntFigures &= "0"
        EndIf
        ; Finally look for units
        For $j = 1 To 9
            If StringInStr($sUnits, $aUnits[$j]) Then
                ; Add value
                $sIntFigures &= $j
                ExitLoop
            EndIf
        Next
        ; Add "0" if no unit value
        If $j > 9 Then
            $sIntFigures &= "0"
        EndIf
    EndIf

    Return $sIntFigures

EndFunc   ;==>_ParseHundred

And the results:

One hundred and three billion five hundred and eleven million two hundred and thirteen thousand seven hundred and fifty five
103,511,213,755
One hundred and three billion two hundred and thirteen thousand seven hundred and fifty five
103,000,213,755
One hundred and three billion eleven million nineteen thousand and one
103,011,019,001
Five hundred and thirteen thousand seven hundred and fifty five
513,755
Five hundred and thirteen thousand
513,000

M23

Edited by Melba23
Fixed leading zero problem - see below
  • Haha 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
TrashBoat

I barely understand what happening in @Deye code, @Melba23

Share this post


Link to post
Share on other sites
Melba23

TrashBoat,

I have commented my code fairly liberally - just ask if you need any further explanation.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
jchd
Posted (edited)

My take at both conversions. I rewrote _IntegerToText as the function mentionned above is buggy.

Local $r, $n

For $i = 1 To 10
    $r = Random(0, 100000000000, 1)
    $n = Random(1, 2000, 1)
    ConsoleWrite("Range is " & $r & " .. " & $r + $n & @LF)
    For $j = 1 To $n
        _Check($r + $j)
    Next
Next

Func _Check($n)
    Local $s = _IntegerToText($n)
    Local $r = _TextToInteger($s)
    ConsoleWrite($r = $n ? "" : $n & " ERROR" & @LF)
EndFunc

Func _CheckDetail($n)
    ConsoleWrite($n & @LF)
    Local $s = _IntegerToText($n)
    ConsoleWrite($s & @LF)
    Local $r = _TextToInteger($s)
    ConsoleWrite($r & @LF)
    ConsoleWrite("-------------- " & ($r = $n ? "OK" : "ERROR") & @LF)
EndFunc

Func _IntegerToText($iNum)
    Local $aGroup3, $iGroup3, $iHundreds, $iTens, $iUnits, $iMultiple, $sText

    If IsString($iNum) Then $iNum = StringStripWS($iNum, 8)
    $iNum = Int($iNum)
    If $iNum = 0 Then
        Return 'zero'
    EndIf

    $iNum = StringRegExpReplace($iNum, '(\A\d{1,3}(?=(\d{3})+\z)|\d{3}(?=\d))', '\1 ')
    $aGroup3 = StringSplit($iNum, ' ', 2)

    Local Static $aWords = [ _
        ['', ' one', ' two', ' three', ' four', ' five', ' six', ' seven', ' eight', ' nine', ' ten', ' eleven', ' twelve', ' thirteen', ' fourteen', ' fifteen', ' sixteen', ' seventeen', ' eighteen', ' nineteen'], _
        ['', '', ' twenty', ' thirty', ' forty', ' fifty', ' sixty', ' seventy', ' eighty', ' ninety'], _
        ['', ' thousand', ' million', ' billion', ' trillion', ' quadrillion', ' quintillion'] _
    ]

    $sText = ''
    $iMultiple = UBound($aGroup3) - 1

    For $i = 0 To UBound($aGroup3) - 1
        $iGroup3 = Int($aGroup3[$i])
        If $iGroup3 = 0 Then
            $iMultiple -= 1
            ContinueLoop
        EndIf

        $iHundreds = Int($iGroup3 / 100)
        $iTens = Int(Mod($iGroup3, 100) / 10)
        $iUnits = Mod($iGroup3, 10)
        $iTwenty = $iTens * 10 + $iUnits


        Switch $iHundreds
            Case 2 To 9
                $sText &= $aWords[0][$iHundreds]
                ContinueCase
            Case 1
                $sText &= " hundred"
        EndSwitch
        If $iTwenty < 20 Then
            $sText &= $aWords[0][$iTwenty]
        Else
            $sText &= $aWords[1][$iTens] & $aWords[0][$iUnits]
        EndIf

        $sText &= $aWords[2][$iMultiple] & ($iMultiple < 2 ? "" : ($iGroup3 > 1 ? "s" : ""))
        $iMultiple -= 1
    Next

    Return StringStripWS($sText, 3)
EndFunc

Func _TextToInteger($sText)

    If IsString($sText) Then $sText = StringStripWS($sText, 8)

    Local Static $s0_9 = "zero|one|two|three|four|five|six|seven|eight|nine"
    Local Static $s10_19 = "ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen"
    Local Static $s20_27 = "twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety"
    Local Static $s28_33 = "thousand|million|billion|trillion|quadrillion|quintillion"
    Local $aExpr = StringRegExp($sText, _
        "(?ix) (?(DEFINE) (?<Range0_9> " & $s0_9 & ") (?<Range10_19> " & $s10_19 & ") (?<Range20_27> " & $s20_27 & ") (?<Range28_33> " & $s28_33 & ") )" & _
        "(?:((?&Range0_9)?) (hundred))?   (?| ((?&Range20_27)) ((?&Range0_9)?) | ()? ((?&Range10_19)) | ()? ((?&Range0_9)) )?   ((?&Range28_33)?)", 3)
    Local Static $a0_19 = StringSplit($s0_9 & "|" & $s10_19, "|", 2)
    Local Static $a20_27 = StringSplit($s20_27, "|", 2)
    Local Static $a28_33 = StringSplit($s28_33, "|", 2)
    Local $iNumber, $iGroupNb, $idx, $iNbGroups = UBound($aExpr) / 9
    For $i = 0 To $iNbGroups - 1
        $iGroupNb = 0
        If $aExpr[9 * $i + 5] Then $iGroupNb = 100
        If $aExpr[9 * $i + 4] Then $iGroupNb *= _ArraySearch($a0_19, $aExpr[9 * $i + 4])
        $idx = _ArraySearch($a20_27, $aExpr[9 * $i + 6])
        If Not @error Then $iGroupNb += 10 * ($idx + 2)
        $idx = _ArraySearch($a0_19, $aExpr[9 * $i + 7])
        If Not @error Then $iGroupNb += $idx
        $idx = _ArraySearch($a28_33, $aExpr[9 * $i + 8])
        If Not @error Then $iGroupNb *= Int(1000 ^ ($idx + 1))
        $iNumber += $iGroupNb
    Next

    Return $iNumber
EndFunc

EDIT: forgot to mention that it's rather easy to add some decoration, like the word "and" or comma as separator of groups of 3 digits, all in both functions.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
TrashBoat

@Deye it seems to have failed on "fourthousandsevenhundredfourtysix" and gave 4706

Share this post


Link to post
Share on other sites
TrashBoat

Yeah my input had broken english, should've payed more attention

Share this post


Link to post
Share on other sites
Malkey
Posted (edited)

@TrashBoat
    "one million, two hundred and thirteen thousand, seven hundred and twenty-five" your script returns
    1213700

@Melba23
    "one million, two hundred and thirteen thousand, seven hundred and twenty-five" your script returns
    001,213,725

@jchd
    "one million, two hundred and thirteen thousand, seven hundred and twenty-five" your script returns
     1013925

And another one.

#include <Array.au3> ; For _ArrayDisplay(), if used.

ConsoleWrite(_Text2Num("twenty") & @CRLF)                                    ; Returns  20
ConsoleWrite(_Text2Num("hundred") & @CRLF)                                   ; Returns 100
ConsoleWrite(_Text2Num("two thousand and eighteen", 0) & @CRLF)              ; Returns 2018  (Comma separator set ot "0")
ConsoleWrite(_Text2Num("A thousand, five hundred and thirty-seven") & @CRLF) ; Returns 1,537
ConsoleWrite(_Text2Num("Twelve billion, eight hundred and forty-four million, three hundred and thirteen thousand, seven hundred and twenty-five") & @CRLF) ; Returns 12,844,313,725
ConsoleWrite(_Text2Num("Million hundred and thirteen thousand, seven hundred and twenty-five") & @CRLF) ; Returns 1,113,725
ConsoleWrite(_Text2Num("A billion hundred eighty-one million, four hundred nine thousand hundred seventy-nine") & @CRLF) ; Returns 1,181,409,179


Func _Text2Num($Txt, $AddThousandsSep = 1)
    Local $sRet = "("
    Local $sD = "zero=+0,one=+1,two=+2,twen=+2,three=+3,thir=+3,for=+4,four=+4,fif=+5,five=+5,six=+6,seven=+7,eigh=+8,eight=+8,nine=+9," & _
            "ten=+10,teen=+10,eleven=+11,twelve=+12,ty=*10,hundred=*100,thousand=)*1000+(,million=)*1000000+(,billion=)*1000000000+("
    Local $sREP = StringTrimRight(StringRegExpReplace($sD, "=\)?[+*]\d+(\+\()?,?", "|"), 1)
    $Txt = StringRegExpReplace($Txt, "(?i)(^|a\h*|,\h*|ion\h*|and\h*)(?=hundred|thousand|million|billion)", "\1 one ") ; Add "one" infront of a hundred, etc., when absent.
    ;ConsoleWrite($Txt & @CRLF) ; View modified $Txt string.

    Local $aArr = StringRegExp($Txt, "(?i)" & $sREP, 3)
    For $i = 0 To UBound($aArr) - 1
        $sRet &= StringRegExpReplace($sD, "(?i)^.*" & $aArr[$i] & "=(\)?[+*]\d+(\+\()?).*$", "$1")
    Next
    ;ConsoleWrite($sRet & ")" & @CRLF) ; See string pre-executed.
    ;_ArrayDisplay($aArr)              ; See array from which the pre-executed string is formed.
    $iRet = Execute($sRet & ")")
    If $AddThousandsSep Then
        Return StringRegExpReplace($iRet, '(\d+?)(?=(\d{3})+\b)', '$1,') ; Add comma separators.
    Else
        Return $iRet
    EndIf
EndFunc   ;==>_Text2Num

 

Edited by Malkey
_Text2Num() modified to allow "a hundred", or just "hundred" to be read as" one hundred".

Share this post


Link to post
Share on other sites
jchd
44 minutes ago, Malkey said:

@jchd
    "one million, two hundred and thirteen thousand, seven hundred and twenty-five" your script returns
     1013925

Maybe, but :
ConsoleWrite(_TextToInteger("one million two hundred thirteen thousand seven hundred twenty five") &@LF)
works fine. I said I didn't bother to handle "and", commas, dashes nor any other cosmetic variation. This isn't hard to add to my code.

BTW, nice code of yours.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Melba23
Posted (edited)
1 hour ago, Malkey said:

@Melba23
    "one million, two hundred and thirteen thousand, seven hundred and twenty-five" your script returns
    001,213,725

Thanks for pointing that out - the algorithm does not do it any more as it now strips any leading zeroes.

M23

Edited by Melba23
Fixed quote

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Deye

Hi jchd,

_IntegerToText("18050152552")
"eighteen billions fifty millions hundred fifty two thousand five hundred fifty two"

 will it be easy to get it fixed to show:
"eighteen billion fifty million one hundred fifty two thousand five hundred fifty two"

Thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • nooneclose
      By nooneclose
      Hey. I'm working on a new project and was wondering if there is a better way to "update" my Column E array. 
      Here is my code: 
      Local $nI  = 0                                                            ;Creates a name index of 0: nI = Name index Local $nII = 1                                                            ;Creates a name index of 1 for second loop: nII = Name Index 2 For    $iN = 0 To $IndexRows Step 1                                       ;Checks the roster for any names that appear twice      For $iN2 = 0 To $IndexRows Step 1          if $d_Names[$nI] == $d_Names[$nII] And $d_Names[$nII] <> "" Then              Local $timeSheetName = _ArraySearch($e_Names, $d_Names[$nI], 0, 0, 0, 0, 1)              ;MsgBox($MB_SYSTEMMODAL, "Found it", $d_Names[$nI] & " In column E on Row " & $timeSheetName)              Local $eI  = $timeSheetName + 1              ;ConsoleWrite($timeSheetName & @CRLF)              ;ConsoleWrite($eI & @CRLF)              ;ConsoleWrite(@CRLF)              _Excel_RangeInsert($OpenWorkbook.ActiveSheet, "E" & $eI & ":F" & $eI, $xlShiftDown)                                                                          ;Inserts a empty cell in columns E and F.              _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $d_Names[$nII], "E" & $eI)                                                                         ;Fills the empty cell in columns E with the doubled name              $aArray_Index = 2                                           ;Array element counter              For $Index = 2 To $IndexRows Step 1                        ;Loops through every row in the Excel file unto no rows are found or a null row is found                  $Array_Value_E = _Excel_RangeRead($OpenWorkbook, Default, "E"&$Index)                  $e_names[$aArray_Index] = $Array_Value_E                ;While the code loops every value in column E is stored in the E array (updating the array)                  $aArray_Index += 1              Next              ExitLoop          EndIf      Next      $nI  += 1      $nII += 1 Next Basically, It checks a roster for people whose name appears twice then inserts a new "row" for that person because they work in two different departments.
      I have to find that name however in Column E if two appear in column D. My code works but I think it is not as efficient as it could be. 
      Any ideas on how to improve the "update" for my array?
      (once it finds the double names in Column D it then searches for that name by going name by name in the Column E array and once it finds it inserts a new row. However, the E array doesn't have that new row stored in it so I have to "update" the array to properly find the next name)
      Any and all tips would be greatly appreciated. 
       
      NOTE: Just assume I'm opening the excel file properly please do not add that code in, it only complicates your answer. 
    • Miliardsto
      By Miliardsto
      Hello Im wondering if using this https://ohtejera.github.io/ImperiusAutoIt/#started
      UDF can i make that I can control my windows application with phone?
      like for example click button Start on android phone and then something would be done in my windows app?
    • nooneclose
      By nooneclose
      How do I properly convert this to Autoit? This is a VBA macro that I recorded in Excel.
       ActiveSheet.Outline.ShowLevels RowLevels:=2 I need this to close my subtotal once it is finished. 
      any help will be greatly appreciated. 
    • iMacg3
      By iMacg3
      Hi,
      I was looking into a way to delete a registry key (not a specific value, an entire key) if it is present. I was considering using RegRead and RegDelete. However, RegRead appears to only read values, not just keys. Is there a way to delete an entire registry key if it is present? I have heard that the below function may help.
       
      #include-once ; #UDF# ======================================================================================================================= ; Title .........: Reads\Search the name of a Key\Subkey\Value ; AutoIt Version : 3.3.8.1 ; Language ......: English ; Description ...: Lists all Keys\Subkeys\Values in a specified registry key ; Author(s) .....: DXRW4E ; Notes .........: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;~ _RegEnumKeyEx ;~ _RegEnumValEx ; =============================================================================================================================== #Region ;**** Global constants and vars **** Global Const $sValueTypes[12] = ["REG_NONE","REG_SZ","REG_EXPAND_SZ","REG_BINARY","REG_DWORD","REG_DWORD_BIG_ENDIAN","REG_LINK","REG_MULTI_SZ","REG_RESOURCE_LIST","REG_FULL_RESOURCE_DESCRIPTOR","REG_RESOURCE_REQUIREMENTS_LIST","REG_QWORD"] #EndRegion ;**** Global constants and vars **** ; #FUNCTION# ======================================================================================================================== ; Name...........: _RegEnumKeyEx ; Description ...: Lists all subkeys in a specified registry key ; Syntax.........: _RegEnumKeyEx($KeyName[, $iFlag = 0[, $sFilter = "*"]]) ; Parameters ....: $KeyName - The registry key to read. ; $iFlag - Optional specifies Recursion (add the flags together for multiple operations): ; |$iFlag = 0 (Default) All Key-SubKeys Recursive Mod ; |$iFlag = 1 All SubKeys Not Recursive Mod ; |$iFlag = 2 Include in ArrayList in the first element $KeyName ; |$iFlag = 16 $sFilter do Case-Sensitive matching (By Default $sFilter do Case-Insensitive matching) ; |$iFlag = 32 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case). ; By Default the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) ; |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp ; |$iFlag = 128 Enum value's name (_RegEnumKeyEx Return a 2D array, maximum Array Size limit is 3999744 Key\Value) ; |$iFlag = 256 Reads a value data, this flag will be ignored if the $iFlag = 128 is not set ; $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") ; Search the Autoit3 helpfile for the word "WildCards" For details. ; $vFilter - Optional the filter to use for ValueName, $vFilter will be ignored if the $iFlag = 128 is not set ; default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") Search the Autoit3 helpfile for the word "WildCards" For details. ; $iValueTypes - Optional, set Value Types to search (Default $iValueTypes = 0 Read All), $iValueTypes will be ignored if the $iFlag = 128 is not set ; (add the flags together for multiple operations): ; 1 = REG_SZ ; 2 = REG_EXPAND_SZ ; 3 = REG_BINARY ; 4 = REG_DWORD ; 5 = REG_DWORD_BIG_ENDIAN ; 6 = REG_LINK ; 7 = REG_MULTI_SZ ; 8 = REG_RESOURCE_LIST ; 9 = REG_FULL_RESOURCE_DESCRIPTOR ; 10 = REG_RESOURCE_REQUIREMENTS_LIST ; 11 = REG_QWORD ; Return values .: Success - Return Array List (See Remarks) ; Failure - @Error ; |1 = Invalid $sFilter ; |2 = No Key-SubKey(s) Found ; |3 = Invalid $vFilter ; |4 = No Value-Name(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: The array returned is one-dimensional and is made up as follows: ; $array[0] = Number of Key-SubKeys returned ; $array[1] = 1st Key\SubKeys ; $array[2] = 2nd Key\SubKeys ; $array[3] = 3rd Key\SubKeys ; $array[n] = nth Key\SubKeys ; ; If is set the $iFlag = 128 The array returned is 2D array and is made up as follows: ; $array[0][0] = Number of Key-SubKeys returned ; $array[1][0] = 1st Key\SubKeys ; $array[1][1] = 1st Value name ; $array[1][2] = 1st Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[1][3] = 1st Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[2][0] = 2nd Key\SubKeys ; $array[2][1] = 2nd Value name ; $array[2][2] = 2nd Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[2][3] = 2nd Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[n][0] = nth Key\SubKeys ; Related .......: _RegEnumValEx() ; Link ..........: ; Example .......: _RegEnumKeyEx("HKEY_CURRENT_USER\Software\AutoIt v3") ; Note ..........: ; =================================================================================================================================== Func _RegEnumKeyEx($KeyName, $iFlag = 0, $sFilter = "*", $vFilter = "*", $iValueTypes = 0) If StringRegExp($sFilter, StringReplace("^\s*$|\v|\\|^\||\|\||\|$", Chr(BitAND($iFlag, 64) + 28) & "\|^\||\|\||\|$", "\\\\")) Then Return SetError(1, 0, "") Local $IndexSubKey[101] = [100], $SubKeyName, $BS = "\", $sKeyList, $I = 1, $sKeyFlag = BitAND($iFlag, 1), $sKeyFilter = StringReplace($sFilter, "*", "") If BitAND($iFlag, 2) Then $sKeyList = @LF & $KeyName If Not BitAND($iFlag, 64) Then $sFilter = StringRegExpReplace(BitAND($iFlag, 16) & "(?i)(", "16\(\?\i\)|\d+", "") & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sFilter, "[^*?|]+", "\\Q$0\\E"), "\\E(?=\||$)", "$0\$"), "(?<=^|\|)\\Q", "^$0"), "\*+", ".*") & ")" While $I $IndexSubKey[$I] += 1 $SubKeyName = RegEnumKey($KeyName, $IndexSubKey[$I]) If @error Then $IndexSubKey[$I] = 0 $I -= 1 $KeyName = StringLeft($KeyName, StringInStr($KeyName, "\", 1, -1) - 1) ContinueLoop EndIf If $sKeyFilter Then If StringRegExp($SubKeyName, $sFilter) Then $sKeyList &= @LF & $KeyName & $BS & $SubKeyName Else $sKeyList &= @LF & $KeyName & $BS & $SubKeyName EndIf If $sKeyFlag Then ContinueLoop $I += 1 If $I > $IndexSubKey[0] Then $IndexSubKey[0] += 100 ReDim $IndexSubKey[$IndexSubKey[0] + 1] EndIf $KeyName &= $BS & $SubKeyName WEnd If Not $sKeyList Then Return SetError(2, 0, "") If BitAND($iFlag, 128) <> 128 Then Return StringSplit(StringTrimLeft($sKeyList, 1), @LF, StringReplace(BitAND($iFlag, 32), "32", 2)) $sKeyList = _RegEnumValEx(StringSplit(StringTrimLeft($sKeyList, 1), @LF), $iFlag, $vFilter, $iValueTypes) Return SetError(@Error, 0, $sKeyList) EndFunc ; #FUNCTION# ======================================================================================================================== ; Name...........: _RegEnumValEx ; Description ...: Lists all values in a specified registry key ; Syntax.........: _RegEnumValEx($KeyName[, $iFlag = 0[, $sFilter = "*"]]) ; Parameters ....: $KeyName - The registry key to read Or one-dimensional array RegKeyList ; use _RegEnumKeyEx() to get $RegKeyList (example $RegKeyList = [3, 1st Key\SubKeys, 2st Key\SubKeys, nth Key\SubKeys]) ; |$iFlag = 16 $sFilter do Case-Sensitive matching (By Default $sFilter do Case-Insensitive matching) ; |$iFlag = 32 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case). ; By Default the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) ; |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp ; |$iFlag = 256 Reads a value data ; $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") ; Search the Autoit3 helpfile for the word "WildCards" For details. ; $iValueTypes - Optional, set Value Types to search (Default $iValueTypes = 0 Read All) ; (add the flags together for multiple operations): ; 1 = REG_SZ ; 2 = REG_EXPAND_SZ ; 3 = REG_BINARY ; 4 = REG_DWORD ; 5 = REG_DWORD_BIG_ENDIAN ; 6 = REG_LINK ; 7 = REG_MULTI_SZ ; 8 = REG_RESOURCE_LIST ; 9 = REG_FULL_RESOURCE_DESCRIPTOR ; 10 = REG_RESOURCE_REQUIREMENTS_LIST ; 11 = REG_QWORD ; Return values .: Success - Return Array List (See Remarks) ; Failure - @Error ; |3 = Invalid $sFilter ; |4 = No Value-Name(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: The array returned is 2D array and is made up as follows: ; $array[0][0] = Number of Key-SubKeys returned ; $array[1][0] = 1st Key\SubKeys ; $array[1][1] = 1st Value name ; $array[1][2] = 1st Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[1][3] = 1st Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[2][0] = 2nd Key\SubKeys ; $array[2][1] = 2nd Value name ; $array[2][2] = 2nd Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[2][3] = 2nd Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[n][0] = nth Key\SubKeys ; Related .......: _RegEnumKeyEx() ; Link ..........: ; Example .......: _RegEnumValEx("HKEY_CURRENT_USER\Software\AutoIt v3") ; Note ..........: ; =================================================================================================================================== Func _RegEnumValEx($aKeyList, $iFlag = 0, $sFilter = "*", $iValueTypes = 0) If StringRegExp($sFilter, "\v") Then Return SetError(3, 0, "") If Not IsArray($aKeyList) Then $aKeyList = StringSplit($aKeyList, @LF) Local $aKeyValList[1954][4], $iKeyVal = Int(BitAND($iFlag, 32) = 0), $sKeyVal = 1953, $sRegEnumVal, $iRegEnumVal, $RegRead = BitAND($iFlag, 256), $vFilter = StringReplace($sFilter, "*", "") If Not BitAND($iFlag, 64) Then $sFilter = StringRegExpReplace(BitAND($iFlag, 16) & "(?i)(", "16\(\?\i\)|\d+", "") & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sFilter, "[^*?|]+", "\\Q$0\\E"), "\\E(?=\||$)", "$0\$"), "(?<=^|\|)\\Q", "^$0"), "\*+", ".*") & ")" For $i = 1 To $aKeyList[0] $iRegEnumVal = 0 While 1 If $iKeyVal = $sKeyVal Then If $sKeyVal = 3999744 Then ExitLoop $sKeyVal *= 2 ReDim $aKeyValList[$sKeyVal + 1][4] EndIf $aKeyValList[$iKeyVal][0] = $aKeyList[$i] $iRegEnumVal += 1 $sRegEnumVal = RegEnumVal($aKeyList[$i], $iRegEnumVal) If @Error <> 0 Then If $iRegEnumVal = 1 And $vFilter = "" Then $iKeyVal += 1 ExitLoop EndIf $aKeyValList[$iKeyVal][2] = $sValueTypes[@Extended] If BitAND(@Extended, $iValueTypes) <> $iValueTypes Then ContinueLoop If $vFilter And Not StringRegExp($sRegEnumVal, $sFilter) Then ContinueLoop $aKeyValList[$iKeyVal][1] = $sRegEnumVal If $RegRead Then $aKeyValList[$iKeyVal][3] = RegRead($aKeyList[$i], $sRegEnumVal) $iKeyVal += 1 WEnd Next $sRegEnumVal = $iKeyVal - Int(BitAND($iFlag, 32) = 0) If Not $sRegEnumVal Or ($sRegEnumVal = 1 And $vFilter = "" And $aKeyValList[$iKeyVal - $sRegEnumVal][2] = "") Then Return SetError(4, 0, "") ReDim $aKeyValList[$iKeyVal][4] If Not BitAND($iFlag, 32) Then $aKeyValList[0][0] = $iKeyVal - 1 Return $aKeyValList EndFunc Thanks.
       
    • great77
      By great77
      ; put the root in a variable $sRoot = "C:\Project\PHexample\" Global $sCurrentTime = _NowCalc() ; We can use that variable here Global $aList = _FileListToArray($sRoot, Default, 2) If @error Then Exit ;;;;;;MsgBox(0, "Error", "_FileListToArray returned @error = " & @error) ;;;;;;;;;;;This is a loop that runs from 1 to the number of items listed in the first element of the returned  array For $i = 1 To UBound($aList) - 1     MsgBox(0, "Folder date", $sRoot & "" & $aList[$i] & @CRLF & @CRLF & FileGetTime($sRoot & "" & $aList[$i], 1, 1))     MsgBox(0, "Folder date", FileGetTime($sRoot & "" & $aList[$i], 1, 1))      $a_filenew = StringReplace(StringReplace(StringReplace(_NowCalc(), "/", ""), ":", ""), " ", "")       MsgBox(0, "Folder date", $a_filenew) $adex =  _DateDiff('D', FileGetTime($sRoot & "" & $aList[$i], 1, 1), $a_filenew)  MsgBox(0,"ade", $adex) Next I have a code as seen above, but the difference in time is returning zero. I understand that the date yyyymmddhhmmss but how can I find the difference.
      The purpose is to try find the difference in days. Any suggestion?  
×