You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
lavos/cap3/ex14.go

25 lines
646 B

package cap3
var _numberTexts = []string{
"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine",
}
// Ex14NumInput 输入数字,输出英文
func Ex14NumInput(num uint64, callback func(str string)) {
digits := make([]uint8, 0, 20)
for i := num; i >= 1; i /= 10 {
digits = append(digits, uint8(i%10))
}
for i := len(digits) - 1; i >= 0; i-- {
callback(_numberTexts[digits[i]])
}
}
// Ex14StrInput 输入数字字符串,输出英文
func Ex14StrInput(num string, callback func(str string)) {
for _, char := range num {
callback(_numberTexts[char-48])
}
}