明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4638|回复: 26

将纯数字字符翻译成汉字数字

    [复制链接]
发表于 2011-9-8 12:05:55 | 显示全部楼层 |阅读模式
本帖最后由 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

点评

顶一下  发表于 2012-3-16 09:19

评分

参与人数 2明经币 +4 金钱 +30 收起 理由
cmdX + 1 很给力!
飞诗(fsxm) + 3 + 30 赞一个!

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2011-9-8 12:28:22 | 显示全部楼层
呵呵,真的不错哦,
 楼主| 发表于 2011-9-8 12:36:11 | 显示全部楼层

板凳

本帖最后由 gbhsu 于 2011-9-8 12:42 编辑

呵呵,沙发有人抢了,自已坐板凳吧!

发表于 2011-9-8 13:06:39 | 显示全部楼层
lsp功能真强大......
发表于 2011-9-8 14:26:05 | 显示全部楼层
你真是个人才啊 这也能做得到
发表于 2011-9-8 14:33:50 | 显示全部楼层
好象不行哦
 楼主| 发表于 2011-9-8 15:38:16 | 显示全部楼层
本帖最后由 gbhsu 于 2011-9-8 15:41 编辑
戏男 发表于 2011-9-8 14:33
好象不行哦
_$ (hsu:num2ch "123456789")
"一亿二千三百四十五万六千七百八十九"
_$


哪里不行?
是不是少函数?
发表于 2011-9-8 16:15:57 | 显示全部楼层
挺有意思的东西,支持。
发表于 2011-9-8 16:17:46 | 显示全部楼层
樓主真是太有才了!!
可惜這lsp我用不上
不然效率提高是可期的
发表于 2011-9-8 16:30:43 | 显示全部楼层
我试了那个命令 不行啊num2ch 就这个命令
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-9 21:09 , Processed in 0.210218 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表