[willing to pay] Looking for a program that will translate letters to #'s [pre-defined]

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Pigeontrue89
Posts: 2
Joined: 08 May 2021, 17:57

[willing to pay] Looking for a program that will translate letters to #'s [pre-defined]

08 May 2021, 18:05

:idea: Does anyone know of a program that will take a number in letter format, for example "onethousandtwohundredsixteen" and translate it into "1216".

I have a text file of the numbers 1-1000 and it needs to read each number in letter format and translate it into text. Any help would be greatly appreciated.

EDIT: I already have the numbers translated in a text file side by side, the bot just has to use OCR to check for the numbers, when it see's them type back (also it's not an image).
User avatar
mikeyww
Posts: 26871
Joined: 09 Sep 2014, 18:38

Re: [willing to pay] Looking for a program that will translate letters to #'s [pre-defined]

08 May 2021, 19:35

This is an idea.

Code: Select all

MsgBox, % stringToNumber("onethousandtwohundredtwentyfive")
MsgBox, % stringToNumber("onethousandtwohundredsixteen")
MsgBox, % stringToNumber("ninehundredone")
MsgBox, % stringToNumber("nineteenthousandfortytwo")
MsgBox, % stringToNumber("nineteenthousandsixhundredfortytwo")
MsgBox, % stringToNumber("twelve")
MsgBox, % stringToNumber("twelvehundred")
MsgBox, % stringToNumber("onethousandtwohundred")
MsgBox, % stringToNumber("twohundredtwenty")
MsgBox, % stringToNumber("one")

stringToNumber(str := "") {
 Static tens  := {twenty:   20, thirty:   30, forty:   40, fifty:   50, sixty:     60, seventy:  70
                , eighty:   80, ninety:   90}
 Static addee := {one:       1, two:       2, three:    3, four:     4, five:       5, six:       6
                , seven:     7, eight:     8, nine:     9, ten:     10, eleven:    11, twelve:   12
                , thirteen: 13, fourteen: 14, fifteen: 15, sixteen: 16, seventeen: 17, eighteen: 18
                , nineteen: 19}
 If (str = "")
  Return 0
 For k, v in [["thousand", 1000], ["hundred", 100]]
  If RegExMatch(str, "(.+)" v.1 "(.*)", part)
   Return v.2 * stringToNumber(part1) + stringToNumber(part2)
 If addee.HasKey(str)
  Return addee[str]
 For k, v in tens
  If RegExMatch(str, k "\K.*", ones)
   Return v + stringToNumber(ones)
}
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: [willing to pay] Looking for a program that will translate letters to #'s [pre-defined]

09 May 2021, 10:18

Don't know where the OP went, but looks like a valid solution to me. Maybe a little neater for readability... :think: Still, another good one mikeyww. :clap:
mikeyww wrote:
08 May 2021, 19:35
This is an idea.

Code: Select all

MsgBox, % stringToNumber("onethousandtwohundredtwentyfive")
MsgBox, % stringToNumber("onethousandtwohundredsixteen")
MsgBox, % stringToNumber("ninehundredone")
MsgBox, % stringToNumber("nineteenthousandfortytwo")
MsgBox, % stringToNumber("nineteenthousandsixhundredfortytwo")
MsgBox, % stringToNumber("twelve")
MsgBox, % stringToNumber("twelvehundred")
MsgBox, % stringToNumber("onethousandtwohundred")
MsgBox, % stringToNumber("twohundredtwenty")
MsgBox, % stringToNumber("one")

stringToNumber(str := "") {
 Static tens  := {twenty:   20, thirty:   30, forty:   40, fifty:   50, sixty:     60, seventy:  70
                , eighty:   80, ninety:   90}
 Static addee := {one:       1, two:       2, three:    3, four:     4, five:       5, six:       6
                , seven:     7, eight:     8, nine:     9, ten:     10, eleven:    11, twelve:   12
                , thirteen: 13, fourteen: 14, fifteen: 15, sixteen: 16, seventeen: 17, eighteen: 18
                , nineteen: 19}
 If (str = "")
  Return 0
 For k, v in [["thousand", 1000], ["hundred", 100]]
  If RegExMatch(str, "(.+)" v.1 "(.*)", part)
   Return v.2 * stringToNumber(part1) + stringToNumber(part2)
 If addee.HasKey(str)
  Return addee[str]
 For k, v in tens
  If RegExMatch(str, k "\K.*", ones)
   Return v + stringToNumber(ones)
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder and 326 guests