[Experimental] Converts a given Kansuji element such as Ichi (1) and Nana (7) to an Arabic. kansuji2arabic_all() converts only Kansuji in the string. kansuji2arabic_num() convert kansuji that contain the positions (e.g. Hyaku, Sen, etc) with the numbers represented by kansuji. kansuji2arabic_str() converts kansuji in a string to numbers represented by kansuji while retaining the non-kansuji characters.

kansuji2arabic(str, convert = TRUE, .under = Inf)

kansuji2arabic_all(str, ...)

kansuji2arabic_num(str, consecutive = c("convert", "non"), ...)

kansuji2arabic_str(
  str,
  consecutive = c("convert", "non"),
  widths = c("all", "halfwidth"),
  ...
)

Arguments

str

Input vector.

convert

If FALSE, will return as numeric. The default value is TRUE, and numeric values are treated as strings.

.under

Number scale to be converted. The default value is infinity.

...

Other arguments to carry over to kansuji2arabic()

consecutive

If you select "convert", any sequence of 1 to 9 kansuji will be replaced with Arabic numerals. If you select "non", any sequence of 1-9 kansuji will not be replaced by Arabic numerals.

widths

If you select "all", both full-width and half-width Arabic numerals are taken into account when calculating kansuji, but if you select "halfwidth", only half-width Arabic numerals are taken into account when calculating kansuji.

Value

a character or numeric.

Examples

kansuji2arabic("\u4e00")
#> [1] "1"
kansuji2arabic(c("\u4e00", "\u767e"))
#> [1] "1"   "100"
kansuji2arabic(c("\u4e00", "\u767e"), convert = FALSE)
#> [1]   1 100
# Keep Kansuji over 1000.
kansuji2arabic(c("\u4e00", "\u767e", "\u5343"), .under = 1000)
#> [1] "1"   "100" "千" 
# Convert all character
kansuji2arabic_all("\u3007\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341")
#> [1] "012345678910"
kansuji2arabic_all("\u516b\u4e01\u76ee")
#> [1] "8丁目"
# Convert kansuji that contain the positions with the numbers represented by kansuji.
kansuji2arabic_num("\u4e00\u5104\u4e8c\u5343\u4e09\u767e\u56db\u5341\u4e94\u4e07")
#> [1] "123450000"
kansuji2arabic_num("\u4e00\u5104\u4e8c\u4e09\u56db\u4e94\u4e07\u516d\u4e03\u516b\u4e5d")
#> [1] "123456789"
# Converts kansuji in a string to numbers represented by kansuji.
kansuji2arabic_str("\u91d1\u4e00\u5104\u4e8c\u5343\u4e09\u767e\u56db\u5341\u4e94\u4e07\u5186")
#> [1] "金123450000円"
kansuji2arabic_str("\u91d1\u4e00\u5104\u4e8c\u4e09\u56db\u4e94\u4e07\u516d\u4e03\u516b\u4e5d\u5186")
#> [1] "金123456789円"
kansuji2arabic_str("\u91d11\u51042345\u4e076789\u5186")
#> [1] "金123456789円"