TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mohan on July 06, 2022, 02:22:02 AM

Title: Convert text string
Post by: mohan on July 06, 2022, 02:22:02 AM
Need help to convert text string

Open Notepad of below
Code - Auto/Visual Lisp: [Select]
  1. "Block1"
  2. "Block2"
  3. "Block3"
  4. "Block4"
  5. "Block5"

Convert as below
Code - Auto/Visual Lisp: [Select]
  1. "Block1,Block2,Block3,Block4,Block5"

Thanks
Title: Re: Convert text string
Post by: BIGAL on July 06, 2022, 05:59:46 AM
Depends on where blockx is coming from else just strcat in a loop..
Title: Re: Convert text string
Post by: Lee Mac on July 06, 2022, 08:39:49 AM
Open the file in Notepad++ and perform the following find/replacements:

(http://lee-mac.com/swamp/findreplace1.png)

Find:
Code: [Select]
"Replace:
Code: [Select]

(http://lee-mac.com/swamp/findreplace2.png)

Find:
Code: [Select]
\r\nReplace:
Code: [Select]
,
Title: Re: Convert text string
Post by: JohnK on July 06, 2022, 10:11:07 AM
Code - Auto/Visual Lisp: [Select]
  1. ;; -Our list of items to `STRCAT`.
  2. (setq lst '("Block1"
  3.             "Block2"
  4.             "Block3"
  5.             "Block4"
  6.             "Block5"))
  7.  
  8. ;------->%
  9. ;; -Establish a counter `i` and a blank string `newstr`.
  10. (setq i 0
  11.       newstr "")
  12.  
  13. ;; -Loop until  1 - the length of the list is greater than the counter.
  14. (while (> (- (length lst) 1) i)
  15.        ;; -Append a comma and join the strings.
  16.        (setq newstr (strcat newstr (nth i lst) ",")
  17.              ;; -Incriment the counter for our loop.
  18.              i (1+ i))
  19.        )
  20. ;; -Join the last element to our new string.
  21. (setq newstr (strcat newstr (last lst)))
  22. ;------->%

This should be a function so we can repeat this process on a string.
Title: Re: Convert text string
Post by: mohan on July 06, 2022, 11:06:59 AM
Open the file in Notepad++ and perform the following find/replacements:

Thanks Lee Mac Sir
In the Notepad++ works but if there will be a Route that could do faster
Title: Re: Convert text string
Post by: Lee Mac on July 06, 2022, 03:15:11 PM
Open the file in Notepad++ and perform the following find/replacements:

Thanks Lee Mac Sir
In the Notepad++ works but if there will be a Route that could do faster

You can record the operations as a macro in Notepad++ so that everything can be performed with a single keyboard shortcut.
Title: Re: Convert text string
Post by: JohnK on July 06, 2022, 03:34:01 PM
Is this an editor question or a Lisp question? -i.e. should this be moved to the general programming forum?
Title: Re: Convert text string
Post by: Lee Mac on July 06, 2022, 03:53:27 PM
Is this an editor question or a Lisp question? -i.e. should this be moved to the general programming forum?

I wasn't sure either - I only tended toward editor because the OP mentioned this:
Open Notepad of below
Title: Re: Convert text string
Post by: jlogan02 on July 06, 2022, 05:11:08 PM
Is this an editor question or a Lisp question? -i.e. should this be moved to the general programming forum?

At any rate your suggestion is library worthy for me. Good starting point!!
Title: Re: Convert text string
Post by: mohan on July 07, 2022, 07:04:44 AM
You can record the operations as a macro in Notepad++ so that everything can be performed with a single keyboard shortcut.
That was amazing Lee Mac sir, thank you so much :smitten:
Title: Re: Convert text string
Post by: JohnK on July 07, 2022, 11:16:55 AM
Is this an editor question or a Lisp question? -i.e. should this be moved to the general programming forum?

I wasn't sure either - I only tended toward editor because the OP mentioned this:
Open Notepad of below

I guess it was an editor question (good guess).
Title: Re: Convert text string
Post by: BIGAL on July 07, 2022, 09:49:09 PM
Why not chuck in Word replace look at "^p" with "," it will add one on end.
Title: Re: Convert text string
Post by: JohnK on July 07, 2022, 10:11:15 PM
Is this an editor question or a Lisp question? -i.e. should this be moved to the general programming forum?

At any rate your suggestion is library worthy for me. Good starting point!!
@jlogan02 I just noticed your reply now (sorry). Well, that's nice of you to say. Thank you.