Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add consecutive letters to end of text string

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
mracad
826 Views, 7 Replies

Add consecutive letters to end of text string

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!!!

7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: mracad

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"

Message 3 of 8
Anonymous
in reply to: Anonymous

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.

Message 4 of 8
Anonymous
in reply to: Anonymous

The return of the Tim 🙂

Message 5 of 8
mracad
in reply to: Anonymous

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)))))))
      )
    )
  )

Message 6 of 8
Anonymous
in reply to: mracad

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!

Message 7 of 8
martti.halminen
in reply to: mracad


@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.

?

Message 8 of 8
Anonymous
in reply to: Anonymous

Thanks, same to you.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost