Author Topic: foreach x lst to mapcar cdr lst  (Read 4492 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: foreach x lst to mapcar cdr lst
« Reply #15 on: October 23, 2011, 07:54:59 AM »
Maybe I missed something but I thought this is correct for removing \\P
("DBA\\" "1" "AAA" "BBB" "CCC")
The first group in plain text should be DBA\

If I've understood, the OP wishes to split the MText string by each line; however, if the "\P" is used within the MText content, it is prefixed with backslashes to mark it as a 'literal' and not be used as a new-line character code.

That is, unless I have misunderstood?

jaydee

  • Guest
Re: foreach x lst to mapcar cdr lst
« Reply #16 on: October 23, 2011, 07:58:59 AM »
Thanks cab and lee.
What i meant was if the string actually contain the string with back slash follow by letter P.
Ie. ABC\P1 as the content.. not the \\P  as for mtext format enter

Cheers

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: foreach x lst to mapcar cdr lst
« Reply #17 on: October 23, 2011, 08:00:21 AM »
OK, I get it now  :-o

Off to get more coffee......
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

jaydee

  • Guest
Re: foreach x lst to mapcar cdr lst
« Reply #18 on: October 23, 2011, 08:04:28 AM »
Thanks cab and lee
Lee is on the dot.

\P  is being use in the string literally as it appear in the screen.

Now i just remember, in the past i have used xpress tool text to mtext alot on older drawing created with dtext. And now i wonder where some of the letter "P" are gone.
That exactly what happen when convert dtext string "Abc\P1" = "Abc\1"
« Last Edit: October 23, 2011, 08:38:20 AM by jaydee »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: foreach x lst to mapcar cdr lst
« Reply #19 on: October 23, 2011, 08:52:19 AM »
How about this instead:

Code: [Select]
(defun MultilineParser ( str / sub )
    (defun sub ( str pos )
        (if (setq pos (vl-string-search "\\P" str pos))
            (if
                (and
                    (< 0 pos)
                    (eq "\\" (substr str pos 1))
                )
                (sub (strcat (substr str 1 (1- pos)) (substr str (1+ pos))) (1+ pos))
                (cons (substr str 1 pos) (sub (substr str (+ pos 3)) 0))
            )
            (list str)
        )
    )
    (sub str 0)
)

(It will remove the extra "\" marking the "\P" as a literal):

Code: [Select]
_$ (MultilineParser "DBA\\\\P1\\PAAA\\PBBB\\PCCC")
("DBA\\P1" "AAA" "BBB" "CCC")

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: foreach x lst to mapcar cdr lst
« Reply #20 on: October 23, 2011, 09:02:30 AM »
Now i just remember, in the past i have used xpress tool text to mtext alot on older drawing created with dtext. And now i wonder where some of the letter "P" are gone.
That exactly what happen when convert dtext string "Abc\P1" = "Abc\1"

This will happen with many strings - any string that contains the equivalent of MText formatting codes, which are not prefixed with backslashes to mark them as literals.

For example, create DText with the string:

Code: [Select]
C:\Computer\LISP
Now use the TXT2MTXT Express Tools function on that DText.  :wink:

I describe this behaviour in more detail here.

jaydee

  • Guest
Re: foreach x lst to mapcar cdr lst
« Reply #21 on: October 23, 2011, 08:34:24 PM »
Thankyou Lee for your help
I admit i dont come across formatted mtext codes use as actual text content, but i rather be safe.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: foreach x lst to mapcar cdr lst
« Reply #22 on: October 24, 2011, 05:56:17 AM »
Thankyou Lee for your help
I admit i dont come across formatted mtext codes use as actual text content, but i rather be safe.

You're welcome :-)

Just be aware of the issue when using backslashes in DText  :wink: