I am having a hard time with figuring out how to add characters to the end of a string.
Each line must have a separate label based on the original line numbering. (example 1-1, 1-120, 50-120, 100-100, etc).
They lines are always 2 numbers separated by a "-".
When I have an attached subline, I need to add an "a" to the to get 1-1a. I thought I could get away with only 26 characters 1-1, 1-1a to 1-1z, but I now need to have an unlimited number.
Once I reach the "z" subline, I need to start over with "aa".
Examples -
1-1
1-1a
1-1b
...
1-1z
next line will be -
1-1aa
1-1ab
...
1-1az
next line will be -
1-1aaa
1-1aab
...
and so forth
What I need is a subroutine to check a Variable and add 1 letter
Here is what I have to start with line without a letter, then add character or increment.
(defun Test ()
(if (= 122 (ascii (substr Current_Wire (strlen Current_Wire))))
(progn
(alert (strcat "\nERROR - Current Wire " Current_Wire " is at maximum letter."))
(exit)
)
)
(if (wcmatch Current_Wire "*#")
(setq Current_Wire (strcat Current_Wire "a"))
(setq Current_Wire (strcat (substr Current_Wire 1 (1- (strlen Current_Wire))) (chr (1+ (ascii (substr Current_Wire (strlen Current_Wire)))))))
)
Current_Wire
)
Thanks in advance!!!
Solved! Go to Solution.
Solved by mracad. Go to Solution.
This should do what you want, if I'm reading the post right. If it doesn't, then it should give you a good head start.
{code}
(defun UpRevisionString (String / tmpPos tmpStr tmpStr2 tmpStr3 EndStr tmpAddValue)
; Update to the new revision. A->B, Z->AA, AZ->BA, AZA->AZB
(setq tmpPos (strlen String))
(while (and (/= tmpPos 0) (= (setq tmpStr (substr String tmpPos 1)) "Z"))
(setq tmpPos (1- tmpPos))
(if tmpStr2
(setq tmpStr2 (strcat "A" tmpStr2))
(setq tmpStr2 "A")
)
)
(if (= tmpPos 0)
(repeat (1+ (strlen String))
(if EndStr
(setq EndStr (strcat EndStr "A"))
(setq EndStr "A")
)
)
(progn
(setq tmpStr3 (substr String 1 (1- tmpPOs)))
(if (or (= tmpStr "H") (= tmpStr "N") (= tmpStr "P"))
(setq tmpAddValue 2)
(setq tmpAddValue 1)
)
(setq tmpStr (chr (+ tmpAddValue (ascii tmpStr))))
)
)
(cond
(EndStr
EndStr
)
((and tmpStr tmpStr2 tmpStr3)
(strcat tmpStr3 tmpStr tmpStr2)
)
((and tmpStr tmpStr3)
(strcat tmpStr3 tmpStr)
)
)
)
{code}
Examples:
Command: (uprevisionstring "A")
"B"
Command: (uprevisionstring "Z")
"AA"
Command: (uprevisionstring "ZA")
"ZB"
Command: (uprevisionstring "ZZ")
"AAA"
Forgot to mention that it will skip ' I, O, Q ' letters, as those can't be used for drawing revisions here, but that is an easy change.
thanks....after reviewing your routine I had an epiphany...here is the updated code -
(defun Circuit_Number_Next ()
(cond
;--current wire ends with a number-------------------
((wcmatch Current_Wire "*#")
(setq Current_Wire (strcat Current_Wire "a"))
)
;--current wire ends with "z"------------------------
((= 122 (ascii (substr Current_Wire (strlen Current_Wire))))
(setq Current_Wire (strcat (substr Current_Wire 1 (1- (strlen Current_Wire))) "aa"))
)
;--increment last letter-----------------------------
(T
(setq Current_Wire (strcat (substr Current_Wire 1 (1- (strlen Current_Wire))) (chr (1+ (ascii (substr Current_Wire (strlen Current_Wire)))))))
)
)
)
You might want to try that code with a number that ends in a ' zz ' and see what happens. That case may not be likely to happen, but I would rather code to make sure that if it happens, then the returned value is correct.
I'm around Buddy, but only post when something hasn't been answered, or I can show another way to skin a cat, as there are a lot of smart people here helping nowadays. Thanks for the warm welcoming, as it put a smile on my face. Have a good one Buddy!
@mracad wrote:I am having a hard time with figuring out how to add characters to the end of a string.
Each line must have a separate label based on the original line numbering. (example 1-1, 1-120, 50-120, 100-100, etc).
They lines are always 2 numbers separated by a "-".
When I have an attached subline, I need to add an "a" to the to get 1-1a. I thought I could get away with only 26 characters 1-1, 1-1a to 1-1z, but I now need to have an unlimited number.
Once I reach the "z" subline, I need to start over with "aa".
Examples -
1-1
1-1a
1-1b
...
1-1z
next line will be -
1-1aa
1-1ab
...
1-1az
next line will be -
1-1aaa
1-1aab
...
Shouldn't that be
1-1az
1-1ba
1-1bb
...
1-1bz
1-1ca
1-1cb
...
...
1-1zz
1-1aaa
etc.
?