关于字符串过滤的问题请教大家。
下面的程序要求是输入“50”程序返回“50”,输入“50+4”返回“50” “4”,输入“50*4”返回“50” “50” “50” “50” ,现在程序只可以实现里面的二种情况,第三种情况怎么也实现不出来,有什么别的方法来提取输入的字符串里面的"单数字“ ”+“ ”*“ 后运行不同的程序。里面的乘号分解用了院长的程序,在这里谢谢院长。(defun c:tt()
(vl-load-com)
(setq auto_text "50*4")
(if (not (wcmatch auto_text "*'**"))
(abc2)
(if (wcmatch auto_text "*+*")
(abc2)
(if (wcmatch auto_text "***")
(abc1)
)
)
)
)
(defun abc1 ( )
(setq nn (vl-string-search "*" auto_text)
t1 (substr auto_text 1 nn)
t2 (substr auto_text (+ nn 2))
)
(if (and (distof t1) (setq n (atoi t2)))
(progn
(setq t3 "")
(repeat (1- n)(setq t3 (strcat t3 t1 "+")))
(setq auto_text (strcat t3 t1))
)
)
(abc2)
)
(defun abc2 ( )
(setq auto_textlen (strlen auto_text))
(setq text_t "")
(setq auto_ss nil)
(while (> auto_textlen 0)
(setq txet_c (substr auto_text 1 1))
(if (/= txet_c "+")
(setq text_t (strcat text_t txet_c))
(if (/= text_t"")
(progn
(setq auto_ss (cons text_t auto_ss))
(setq text_t ""))))
(setq auto_text (substr auto_text 2 (- (strlen auto_text) 1)))
(if (and (< auto_textlen 2) (/= text_t""))
(progn
(setq auto_ss (cons text_t auto_ss))
(setq text_t "")))
(setq auto_textlen (1- auto_textlen)))
(setq auto_ss (reverse auto_ss))
)
你可以试试把字符串转换成字符代码表来搜索判别。
vl-string->list 本帖最后由 ivde 于 2015-11-23 11:30 编辑
(defun abc2 (str / lst nlst)
(if (and (wcmatch str "*+*")
(setq str (vl-string-translate "+" " " str))
(setq lst (read (strcat "(" str ")")))
(= (length lst) 2)
(vl-every 'numberp lst)
)
(progn
(repeat (fix (cadr lst))
(setq nlst (cons (car lst) nlst))
)
)
)
(mapcar 'vl-princ-to-string nlst)
) 不知道是不是要这样的效果
谢谢大家,就是“琴剑江山_10184”演示的效果,再次谢谢“琴剑江山_10184”。 请教“琴剑江山_10184”(t (setq text str))这行该怎么理解? 琴剑江山_10184 发表于 2015-11-23 11:50 static/image/common/back.gif
不知道是不是要这样的效果
请教“琴剑江山_10184”(t (setq text str))这行该怎么理解? lxdz443 发表于 2015-11-24 08:44 static/image/common/back.gif
请教“琴剑江山_10184”(t (setq text str))这行该怎么理解?
cond的退出条件,放在最后,也就是前面几种条件都不符合,则执行(setq text str) 谢谢,可以学习学习. 感谢 琴剑江山_10184 分享程序!!!!!
页:
[1]
2