本帖最后由 cabinsummer 于 2011-10-30 17:08 编辑
inpos是一个自定义函数,将字符串str中的分隔符sep前后的分别读出来放到一个表中。分隔符可以为多个字符
- (defun inpos(sep str / pos prestr sufstr russtr)
- (while (setq pos (vl-string-search sep str))
- (setq prestr (substr str 1 pos))
- (setq str (substr str (+ pos 1 (strlen sep))))
- (setq russtr (append russtr (list prestr)))
- )
- (setq russtr (append russtr (list str)))
- )
- (setq sep "=")
- (setq str "红色=1")
- (setq a (inpos sep str));;;a为("红色" "1"),可用(car a)调用"红色",(cadr a)调用"1"
- (setq str "随层=256")
- (setq b (inpos sep str));;;b为("随层" "256"),可用(car b)调用"随层",(cadr b)调用"256"
- (setq sep "通道")
- (setq str "明经通道论坛")
- (setq c (inpos sep str));;;c为("明经" "论坛"),可用(car c)调用"明经",(cadr c)调用"论坛"
- (setq sep "-")
- (setq str "1-2-3-4-5")
- (setq d (inpos sep str));;;d为("1" "2" "3" "4" "5")
- (setq sep "**")
- (setq str "明**经**通**道**论**坛")
- (setq e (inpos sep str));;;e为("明" "经" "通" "道" "论" "坛")
|