(AphaIncrement "A" -1) = "Z"are you sure about this one?
(AphaIncrement "A" -1) = "Z"are you sure about this one?
http://lee-mac.com/columnreference.html#incalpha
You need a representation for zero. If "A" is the first digit it follows that it represents zero. But this is counterintuitive. And if "A" is zero then "AA" is zero as well.(AphaIncrement "A" -1) = "Z"are you sure about this one?
You're right....no sense..it must be nil or "A"
+1
You need a representation for zero. If "A" is the first digit it follows that it represents zero. But this is counterintuitive. And if "A" is zero then "AA" is zero as well.i believe Lee's code is written to deal with MS Excel, so it's got no zero
(defun vk_AlphaBet2Dec (ABC AlphaBet / Len)
(setq Len (strlen AlphaBet))
(if (/= ABC "")
(+ (* (expt Len (1- (strlen ABC)))
(vl-string-position (ascii (substr ABC 1 1)) AlphaBet)
)
(vk_AlphaBet2Dec (substr ABC 2) AlphaBet)
)
0
)
)
(defun vk_Dec2AlphaBet (Dec AlphaBet / Len)
(setq Len (strlen AlphaBet))
(if (< Dec Len)
(substr AlphaBet (1+ Dec) 1)
(strcat (vk_Dec2AlphaBet (/ Dec Len) AlphaBet)
(substr AlphaBet (1+ (rem Dec Len)) 1)
)
)
)
(vk_Dec2AlphaBet 35 "01")
(vk_Dec2AlphaBet 35 "0123456789")
(vk_Dec2AlphaBet 35 "0123456789ABCDEF")
(vk_Dec2AlphaBet 35 "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
(vk_Dec2AlphaBet 35 "Aa")
(vk_Dec2AlphaBet 35 "theSwamp")
(defun ALE_ZetaStrIncVal (ZetStr IncVal / SttStr SttLen)
(if (eq "" (setq SttStr (vl-string-right-trim "Z" ZetStr)))
(strcat (vl-string-translate "Z" "A" ZetStr) "A")
(strcat
(substr SttStr 1 (setq SttLen (1- (strlen SttStr))))
(chr (+ IncVal (vl-string-elt SttStr SttLen)))
(if (eq ZetStr SttStr)
""
(vl-string-translate "Z" "A" (substr ZetStr (+ 2 SttLen)))
)
)
)
)
(ALE_ZetaStrIncVal "A" 1) "B"
(ALE_ZetaStrIncVal "D" 3) "G"
(ALE_ZetaStrIncVal "AAP" 1) "AAQ"
(ALE_ZetaStrIncVal "BAU" 2) "BAW"
(ALE_ZetaStrIncVal "A" -1) "@" <<<<<<<<<<<<<<<<<
(ALE_ZetaStrIncVal "FFFC" 2) "FFFE"
(defun AA:setcar (startwith increment / carpref iba_alphabet cval str# startwith2 nextcar newstartwith)
(setq startwith2 startwith)
(if (< (ascii (substr startwith 1 1)) 96)
(setq cval 64)
(setq cval 96)
)
(setq iba_alphabet nil)
(repeat 26
(setq iba_alphabet (append iba_alphabet (list (chr (setq cval (1+ cval))))))
)
(setq carpref "")
(if (> (setq str# (strlen startwith2)) 1)
(progn (setq carpref (substr startwith2 1 (1- str#)))
(setq startwith2 (substr startwith2 str#))
)
)
(if (not
(setq nextcar (nth (+ increment (vl-position startwith2 iba_alphabet))
iba_alphabet
)
)
)
(progn (setq carpref startwith)
(if (> (setq str# (strlen startwith2)) 1)
(progn (setq carpref (substr startwith2 1 (1- str#)))
(setq startwith2 (substr startwith2 str#))
)
)
(setq nextcar startwith2)
)
)
(setq newstartwith (strcat carpref nextcar))
)
(ALE_ZetaStrIncVal "aa" -1) = "a`" I think it must be "z" ?
(LM:incalpha "a" 1) = "AH" ? lowercase ?
(incsuff "aB" 1 7) = work perfectly
(aa:setcar "BB" -1) = "BA"
(aa:setcar "BA" -1) = Error :)
this is my quick attempt..Comando: (AA:SETCAR "A" -1)
Working with negative value and Upper or lower case :smitten:
Test Made:Why? See your Reply #4 on: Today at 03:54:31 »Code: [Select](ALE_ZetaStrIncVal "aa" -1) = "a`" I think it must be "z" ?
Comando: (ALE_ZetaStrIncVal "aa" -1) > "a`"
Comando: (incsuff "aa" -1 7) > "a`"
Comando: (ALE_ZetaStrIncVal "aB" 1) > "aC"
Comando: (incsuff "aB" 1 7) > "aC"
Test Made:Why? See your Reply #4 on: Today at 03:54:31 »Code: [Select](ALE_ZetaStrIncVal "aa" -1) = "a`" I think it must be "z" ?
Merci Andrea,Use it and a great tool
This routine has been used as base routine in the "Increment (http://gilecad.azurewebsites.net/LISP/Increment.lsp)" LISP suite which is the ancestor of the quite popular .NET "Increment (https://apps.autodesk.com/ACD/en/Detail/Index?id=8051485828049059617&appLang=en&os=Win32_64)" plugin on Exchange Apps.
Non so se ti sbagli ma tutte queste funzioni danno lo stesso risultato:Test Made:Why? See your Reply #4 on: Today at 03:54:31 »Code: [Select](ALE_ZetaStrIncVal "aa" -1) = "a`" I think it must be "z" ?
..x...y...z...aa...ab...ac...ad ?
so (aa - 1) must be "z" ?
forse mi sbaglio ?
(LM:incalpha "aa" -1) => "a`"
(ALE_ZetaStrIncVal "aa" -1) => "a`"
(incsuff "aa" -1 7) => "a`"
I found a bug with my function :oops: :Code - Auto/Visual Lisp: [Select]
_$ (LM:incalpha "Y" 1) "@"
The following should fix it and allow for lowercase:Code - Auto/Visual Lisp: [Select]
;; Increment Alpha - Lee Mac ;; Increments an uppercase alphabetical string by a given number of units, e.g. AX + 4 = BB ;; a - [str] alphabetical string ;; i - [int] integer increment (cond ) ) ) ) )
(LM:incalpha "D" 1);==>>"F"
(LM:incalpha "d" 1);==>>"f"
Code: [Select](LM:incalpha "D" 1);==>>"F"
(LM:incalpha "d" 1);==>>"f"
(ai "A" 1) ;;>>> "B"
(ai "D" 3) ;;>>> "G"
(ai "AAP" 1) ;;>>> "AAQ"
(ai "BAU" 2) ;;>>> "BAW"
(ai "A" -1) ;;>>> "Z"
(ai "FFFC" 2) ;;>>> "FFFE"
(ai "Z" 1) ;;>>> "AA"
(ai "Z" -1) ;;>>> "Y"
(ai "a" 1) ;;>>> "b"
(ai "d" 3) ;;>>> "g"
(ai "aap" 1) ;;>>> "aaq"
(ai "bau" 2) ;;>>> "baw"
(ai "a" -1) ;;>>> "z"
(ai "fffc" 2) ;;>>> "fffe"
(ai "z" 1) ;;>>> "aa"
(ai "z" -1) ;;>>> "y"
(ai "y" -1) ;;>>> "x"
(ai "AA" -1) ;;>>> "AZ"
(ai "zz" 1) ;;>>> "zaa"
(ff "aa" -200);;>>> ""
(ff "aa" 200);;>>> "hs"
(ff "aa" 2000);;>>> "byy"
(ff "aa" -2000);;>>> ""
(ff "AA" -200) ;;>>> ""
(ff "AA" 200);;>>> "HS"
(ff "aA" -200) ;;>>> ""
(ff "aA" 200);;>>> "hs"
(ff "Aa" -200) ;;>>> ""
(ff "Aa" 200);;>>> "HS"
(ff "AA" -1) ;;>>> "A"
(ff "A" 1) ;;>>> "B"
(ff "A" -1) ;;>>> ""
(ff "A" 1) ;;>>> "B"
(ff "D" 3) ;;>>> "G"
(ff "AAP" 1) ;;>>> "AAQ"
(ff "BAU" 2) ;;>>> "BAW"
(ff "A" -1) ;;>>> ""
(ff "FFFC" 2) ;;>>> "FFFE"
(ff "Z" 1) ;;>>> "AA"
(ff "Z" -1) ;;>>> "Y"
(ff "a" 1) ;;>>> "b"
(ff "d" 3) ;;>>> "g"
(ff "aap" 1) ;;>>> "aaq"
(ff "bau" 2) ;;>>> "baw"
(ff "a" -1) ;;>>> ""
(ff "fffc" 2) ;;>>> "fffe"
(ff "z" 1) ;;>>> "aa"
(ff "z" -1) ;;>>> "y"
(ff "y" -1) ;;>>> "x"
(ff "b" -1) => "a"
(ff "aa" -1) => "a"
_$ (ff "a" 25)
"a"
_$ (ff "a" 701)
"{"
(defun _Map32 ( )
;; © Michael Puckett
(setq **map32**
(vl-string->list
;; Note the omission of letters I,L,O,Q
"0123456789ABCDEFGHJKMNPRSTUVWXYZ"
)
)
(defun _Map32 ( ) **map32**)
**map32**
)
(defun _ToMap ( i map )
;; © Michael Puckett
( (lambda ( mask shift / result )
(while (not (zerop i))
(setq
result (cons (nth (logand mask i) map) result)
i (lsh i shift)
)
)
(vl-list->string result)
)
(1- (length map))
(- (fix (/ (log (length map)) (log 2))))
)
)
(defun _FromMap ( x map )
;; © Michael Puckett
( (lambda ( x map shift result )
(while x
(setq result (+ result (length (member (car x) map))))
(if (setq x (cdr x)) (setq result (lsh result shift)))
)
result
)
(mapcar 'chr (vl-string->list x))
(mapcar 'chr (reverse (cdr map)))
(fix (/ (log (length map)) (log 2)))
0
)
)
(defun _To32 ( i )
;; © Michael Puckett
(_ToMap i (_Map32))
)
(defun _From32 ( x )
;; © Michael Puckett
(_FromMap x (_Map32))
)
(defun _Inc32 ( x i )
;; © Michael Puckett
(_To32 (+ i (_From32 x)))
)
...
FWIW / Have fun.
Cheers.
I've never used LOGAND function with negative numbers...Code - Auto/Visual Lisp: [Select]