我会问同样的问题,尽管这可以使用:
- ; _$ (GetNumVal "abc256def,ghi1j3k4x") -> 256.134
- (defun GetNumVal ( str / delimUsed )
- (if (eq 'STR (type str))
- (atof
- (vl-string-subst "." ","
- (apply 'strcat
- (vl-remove 'nil
- (mapcar
- (function
- (lambda (x)
- (if (member x (mapcar 'chr (vl-string->list "1234567890.,")))
- (cond
- ((and (member x '("." ",")) (not delimUsed) (setq delimUsed T))
- x
- )
- ((and (member x '("." ",")) delimUsed) nil)
- (T x)
- ); cond
- ); if
- ); lambda
- ); funciton
- (mapcar 'chr (vl-string->list str))
- ); mapcar
- ); vl-remove
- ); apply 'strcat
- ); vl-string-subst
- ); atof
- ); if
- ); defun GetNumVal
以及不推荐字符串的示例:
- ; _$ (GetNumVal "245.5x640.2") -> 245.564
|