Author Topic: Convert text string  (Read 394 times)

0 Members and 1 Guest are viewing this topic.

mohan

  • Newt
  • Posts: 78
Convert text string
« 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
"Save Energy"

BIGAL

  • Swamp Rat
  • Posts: 1032
  • 40 + years of using Autocad
Re: Convert text string
« Reply #1 on: July 06, 2022, 05:59:46 AM »
Depends on where blockx is coming from else just strcat in a loop..
A man who never made a mistake never made anything

Lee Mac

  • Seagull
  • Posts: 12696
  • London, England
Re: Convert text string
« Reply #2 on: July 06, 2022, 08:39:49 AM »
Open the file in Notepad++ and perform the following find/replacements:



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



Find:
Code: [Select]
\r\nReplace:
Code: [Select]
,
« Last Edit: July 06, 2022, 08:42:52 AM by Lee Mac »

JohnK

  • Administrator
  • Seagull
  • Posts: 10139
Re: Convert text string
« Reply #3 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.
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

mohan

  • Newt
  • Posts: 78
Re: Convert text string
« Reply #4 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
"Save Energy"

Lee Mac

  • Seagull
  • Posts: 12696
  • London, England
Re: Convert text string
« Reply #5 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.

JohnK

  • Administrator
  • Seagull
  • Posts: 10139
Re: Convert text string
« Reply #6 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?
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12696
  • London, England
Re: Convert text string
« Reply #7 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

jlogan02

  • Bull Frog
  • Posts: 273
Re: Convert text string
« Reply #8 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!!
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

mohan

  • Newt
  • Posts: 78
Re: Convert text string
« Reply #9 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:
"Save Energy"

JohnK

  • Administrator
  • Seagull
  • Posts: 10139
Re: Convert text string
« Reply #10 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).
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

BIGAL

  • Swamp Rat
  • Posts: 1032
  • 40 + years of using Autocad
Re: Convert text string
« Reply #11 on: July 07, 2022, 09:49:09 PM »
Why not chuck in Word replace look at "^p" with "," it will add one on end.
A man who never made a mistake never made anything

JohnK

  • Administrator
  • Seagull
  • Posts: 10139
Re: Convert text string
« Reply #12 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.
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org