- ; By Bill Kramer
- (defun String_To_Numbers (
- inStr ;;Input string
- /
- Res ;;Result list
- Buf ;;String buffer
- Inx ;;Character location
- CH ;;Character
- )
- (setq Inx 1 ;start at the beginning of the string
- Buf "" ;init buffer to empty
- )
- ;
- ; Loop until the end of the string.
- ; (I indicates where we are in the string)
- ;
- (while (<= Inx (strlen inStr))
- ;
- ; Get the character at position Inx, increment position indicator
- (setq CH (substr inStr Inx 1)
- Inx (1+ Inx)
- )
- ;
- (cond
- ; Test to see if character is a digit.
- ((wcmatch CH "[0-9.]")
- (if (= CH ".") ;is it decimal?
- (if (not (wcmatch Buf "*`.*")) ;not already in there
- (setq Buf (strcat Buf CH))
- (Flush_Buf))
- ;
- (setq Buf (strcat Buf CH)))
- )
- ((= Buf "") ;is the buffer empty?
- ;Is CH minus
- (if (= CH "-")
- (setq Buf CH) ;Yes, save in Buf
- )
- )
- ('T ;else buffer is not empty
- (Flush_Buf)
- (if (= CH "-")
- (setq Buf CH))
- )
- ); End of COND
- ); End of WHILE
- ;
- (if (and (/= Buf "")
- (not (wcmatch Buf "[+-.]"))
- )
- (Flush_Buf))
- (reverse Res)
- )
- ;
- ; ------------------------------------------------------ Listing 4.5
- ;
- (defun Flush_Buf ()
- (if (not (wcmatch Buf "[+-.]")) ;is it not just +-.?
- (progn
- ;Clean it up first
- (if (= (substr Buf 1 1) ".")
- (setq Buf (strcat "0" Buf))) ;;add zero to front if .#
- (if (= (substr Buf (strlen Buf)) ".")
- (setq Buf (substr Buf 1 (1- (strlen Buf))))) ;;remove decimal if #.
- ;Add to RES list
- (setq RES (cons Buf RES))))
- (setq Buf "") ;;reset Buf
- )
|