func convertNumerialStringToNumberWithString(_ string : String) -> String {
let japaneseNumericalExpChars : [String : String] = [
"十": "1",
"百": "2",
"千": "3",
"万": "4",
"億": "8",
]
let japaneseExpChars : Set = Set(japaneseNumericalExpChars.keys)
let convStr : String = string.characters.reversed().reduce("", {
if $0.0.isEmpty {
if japaneseExpChars.contains($0.1.description) {
return expStr(japaneseNumericalExpChars[$0.1.description]!, isOnlyZero: false)
} else {
return convertCharToStr1To9($0.1)
}
}
if japaneseExpChars.contains($0.1.description) {
return String(Int($0.0)! + Int(expStr(japaneseNumericalExpChars[$0.1.description]!, isOnlyZero: false))!)
} else {
return convertCharToStr1To9($0.1) + $0.0.substring(from: $0.0.index(after: $0.0.startIndex))
}
})
return convStr
}
github.com