- 积分
- 7796
- 明经币
- 个
- 注册时间
- 2010-1-29
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 gbhsu 于 2011-9-8 16:56 编辑
;;;本人原创:将纯数字转变为汉字数字字符
;;;快过中秋了,给大家送点小礼物
;;;原想将cmd+num升级版发出来的,由于工作量大,且要增加不少命令
;;;看来是来不及了
;;;现将前不久鼓捣的一个小子程贴出来大家讨论一下
;;;数字大了,可能有点小问题,正如林子大了,什么鸟都有一样
;;;大家帮忙赶一赶
;;;e.g.(hsu:num2ch "123")"一百二十三"
;;;因在cad中的数值文字是以字符的形式存在的
;;;测试命令为" tt" 专为戏男而编!
(defun c:tt(/ numstr)
(setq numstr (getstring "\n请输入数字字符:"))
(if numstr (hsu:num2ch numstr))
)
(defun hsu:num2ch(str / len strlist hzlist strch listi i j name)
(vl-load-com)
(setq len (strlen str)i 0 hzlist '()listi '())
(setq strlist (reverse(VL-STRING->LIST str)))
(while strlist
(if (or(= i 4)(= i len))
(progn
(setq i 0)
(setq hzlist (append (list listi) hzlist))
(setq listi'())
)
(progn
(setq i (+ i 1))
(setq listi (append (list(car strlist)) listi))
(setq strlist (cdr strlist))
);progn
);if
);repeat
(if listi (setq hzlist (append (list listi) hzlist)))
(setq hzlist (reverse hzlist)i 0 strch "" name "")
;hzlist
(foreach n hzlist
(cond ((= i 1)(if(or
(/=(nth 0 n)48)
(/=(nth 1 n)48)
(/=(nth 2 n)48)
(/=(nth 3 n)48))
(setq name "万")
(setq name "零")))
((= i 2)(if(or
(/=(nth 0 n)48)
(/=(nth 1 n)48)
(/=(nth 2 n)48)
(/=(nth 3 n)48))
(setq name "亿")
(setq name "零")))
((= i 3)(if(or
(/=(nth 0 n)48)
(/=(nth 1 n)48)
(/=(nth 2 n)48)
(/=(nth 3 n)48))
(setq name "兆")
(setq name "零")))
);cond
(setq j i)
(setq strch (strcat (hsu:num2hz n) name strch))
(setq i (+ i 1))
);foreach
(setq len (strlen strch))
(if(=(substr strch 1 4 )"一十")(setq strch (substr strch 3)))
(while (vl-string-search "零零" strch)
(setq strch(vl-string-subst "零""零零" strch)))
strch
);defun
(defun hsu:num2hz(plist / string i)
(vl-load-com)
(setq i 0)
(setq plist(reverse plist))
(setq string '())
(foreach n plist
(setq string (append string
(list
(cond
((= n 48)"零")
((= n 49)"一")
((= n 50)"二")
((= n 51)"三")
((= n 52)"四")
((= n 53)"五")
((= n 54)"六")
((= n 55)"七")
((= n 56)"八")
((= n 57)"九")
);cond
(cond
((and(<= j 3)(= i 0))(if(/=(nth (+ i 1) plist)48)"十" ""))
((and(<= j 3)(= i 1))(if(/=(nth (+ i 1) plist)48)"百" ""))
((and(<= j 3)(= i 2))(if(/=(nth (+ i 1) plist)48)"千" ""))
((and(<= j 3)(= i 3))(if(/=(nth (+ i 1) plist)48)"万" ""))
((and(<= j 3)(= i 4))(if(/=(nth (+ i 1) plist)48)"亿" ""))
((and(<= j 3)(= i 5))(if(/=(nth (+ i 1) plist)48)"兆" ""))
(if(> j 3)"")
);cond
);list
);cond
);setq
(setq i (+ i 1))
);foreach
(while(or(eq(car string)"零")(eq(car string)""))(setq string(cdr string)))
(setq string(apply 'strcat (cdr (reverse string))))
);defun
|
评分
-
查看全部评分
|