搜索字符串是完整的目标字符串还是包含在目标字符串(子字符串)中?
搜索字符串和替换字符串是字符串值还是变量?
你可以做的第一件事是为你的翻译建立一个参考列表
,我会对你的意图做出一些假设。
-
- (setq translationList
- (list (list "C1" "C12")
- (list "C5" "C62")
- (list "TOP" "BTM")
- (list "SO" "ON")
-
- )
- )
-
-
- (defun getRef (key)
- (cdr (assoc key translationList))
- )
-
-
- ;; Test the function just to be sure
- (getRef "CAT") ;;==> nil
- (getref "TOP") ;;==> ("BTM")
- (car (getRef "CAT") ) ;;==> nil
- (car (getRef "C1") ) ;;==> "C12"
-
-
-
-
- ;; Now write a tester
- (setq targetString "C5" )
- (if (setq replacement (car (getRef targetString) ))
- (setq targetString replacement)
- )
-
- (alert (strcat "targetString value is now\n" targetString))
|