[GLLUG] Changing words into numbers

Jason Clifford jason at ukpost.com
Tue Aug 14 10:03:59 UTC 2018


I'm fairly sure there is already a Perl module that does this

---- On Tue, 14 Aug 2018 10:46:18 +0100 gllug at mailman.lug.org.uk wrote ----

Dear list,

A problem which I think has a philosophical side as much as a practical one:
What is the best way (or what are the ways) to replace numbers written 
out in words with digits?
(e.g. "the year one thousand eight hundred and seventy six" to 1776, or 
"nine hundred and ninety pounds" to 999 pounds).

One obvious solution I've thought of is to automatically generate a list 
of all numbers spelled out from one to n, pair them with the numerical 
value, then simply loop through the list and target texts substituting 
the former with the latter. But this strikes me as very blunt and very 
uneconomical. And probably impracical in that the top most number may be 
very high (I don't know what the highest number in the texts I have is, 
though I have seen 'thirty-eight million nine hundred and ninety-seven').

Could there be a regex solution that generates the number from the words?

What other approaches could I take?

Thanks in advance,

John

-- 

John Levin
http://www.anterotesis.com
http://twitter.com/anterotesis
https://hcommons.org/members/johnlevin/

-- 
GLLUG mailing list
GLLUG at mailman.lug.org.uk
https://mailman.lug.org.uk/mailman/listinfo/gllug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20180814/358eae5d/attachment.html>


More information about the GLLUG mailing list