Converting Words to Numbers in Java

前端 未结 6 926
深忆病人
深忆病人 2020-12-09 19:24

I have seen a lot of algorithms in which you give them a number say \"123\" and it converts it to One hundred twenty three. But i can\'t seem to find something that does the

6条回答
  •  北海茫月
    2020-12-09 19:38

    Full credit to Kartic for the elegant answer. I've added to it to allow for processing a large block of text with these types of "word numbers" dispersed inside of it. Not as clean as I hoped since I have to process it without losing any formatting.

    It's a work in progress but might be of some use to people: https://github.com/jgraham0325/words-to-numbers/blob/master/src/main/java/org/jg/wordstonumbers/WordsToNumbersUtil.java

提交回复
热议问题