- function zhongwen ()
- {
- $a = [ordered] @{"零"=0; "一"=1; "二"=2; "三"=3; "四"=4; "五"=5; "六"=6; "七"=7; "八"=8; "九"=9}
- $b = [ordered] @{"十"=10; "百"=100; "千"=1000}
- $c = [ordered] @{"万"=10000}
- $d = [ordered] @{"亿"=100000000}
-
- $str = $args[0] -replace "(?<=^|[^一二三四五六七八九])十","一十"
- $x = $str -split ""
-
- [long[]] $ss = @(0) * 3
- $i = 0
- while ($i -le $x.count)
- {
- $i++
- $s = $x[$i]
- if ($a.keys -contains $s)
- {
- $ss[0] = $ss[0] * 10 + $a[$s]
- } elseif ($b.keys -contains $s)
- {
- $ss[1] += $ss[0] * $b[$s]
- $ss[0] = 0
- } elseif ($c.keys -contains $s)
- {
- $ss[1] = ($ss[1] + $ss[0]) * $c[$s]
- $ss[0] = 0
- } elseif ($d.keys -contains $s)
- {
- $ss[2] = ($ss[2] + $ss[1] + $ss[0]) * $d[$s]
- $ss[1] = 0
- $ss[0] = 0
- } elseif ($s -eq "")
- {
- $ss[2] = $ss[2] + $ss[1] + $ss[0]
- $ss[1] = 0
- $ss[0] = 0
- }
- }
-
- return $ss[2]
- }
-
- dir |?{$_ -match "一|二|三|四|五|六|七|八|九|十|百|千|零"}|ren -newname{
- $oldnumber=[regex]::matches($_.name,'一|二|三|四|五|六|七|八|九|十|百|千|零').value -join ""
- $newnumber=zhongwen $oldnumber
- $_.name.replace($oldnumber,$newnumber)
- }
复制代码
|