Including preceding zeros in angle
Hi there,
Using Lisp I would like to get an angle in surveyor units to include preceding zeros.
Example: N 7d 3' 5" W
I would like the text to show as N 07d 03' 05" W
Is this possible? I can substitute the "d" for the degree symbol but I'm not sure how I might get the preceding zeros.
Thanks in advance for your help.
Phillip
Comments
-
Solution 1:
; (PadSingleDigits "N 7d 3' 5\" W") => "N 07d 03' 05\" W" ; (PadSingleDigits "N 11d 3' 5\" W") => "N 11d 03' 05\" W" ; (PadSingleDigits "A1B23C4") => "A01B23C04" (defun PadSingleDigits (str / lst) (vl-list->string (apply 'append (mapcar '(lambda (pre cur nex) (if (and (<= 48 cur 57) (not (<= 48 pre 57)) (not (<= 48 nex 57)) ) (list 48 cur) (list cur) ) ) (append '(65) (setq lst (vl-string->list str))) lst (append (cdr lst) '(65)) ) ) ) )
Solution 2:; (PadSurveyorUnits "N 7d 3' 5\" W") => "N 07d 03' 05\" W" ; (PadSurveyorUnits "N 11d 3' 5\" W") => "N 11d 03' 05\" W" ; (PadSurveyorUnits "N 7d 3' W") => "N 07d 03' W\"" ; (PadSurveyorUnits "N 7d 5\" W") => "N 07d 05' W\"" ; ERROR. (defun PadSurveyorUnits (str) (apply 'strcat (mapcar '(lambda (sub uni) (if (wcmatch sub "~*#,*##") (strcat sub uni) (strcat (substr sub 1 (1- (strlen sub))) "0" (substr sub (strlen sub)) uni) ) ) (vle-string-split "d'\"" str) '("d" "'" "\"" "") ) ) )
Solution 3:; (PadSingleDigitsAlt "N 7d 3' 5\" W") => "N 07d 03' 05\" W" ; (PadSingleDigitsAlt "N 11d 3' 5\" W") => "N 11d 03' 05\" W" ; (PadSingleDigitsAlt "A1B23C4") => "A01B23C04" (defun PadSingleDigitsAlt (str / lst ret) (setq lst (vl-string->list str)) (while lst (cond ((not (<= 48 (car lst) 57)) (setq ret (cons (car lst) ret)) (setq lst (cdr lst)) ) ((<= 48 (cadr lst) 57) (while (<= 48 (car lst) 57) (setq ret (cons (car lst) ret)) (setq lst (cdr lst)) ) ) (T (setq ret (vl-list* (car lst) 48 ret)) (setq lst (cdr lst)) ) ) ) (vl-list->string (reverse ret)) )
0 -
Thank you Roy for your help!
That's wonderful.
Phillip
0