TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jaydee on October 22, 2011, 09:22:13 AM
-
Hi.
Please show me how to do this
Lst1 '("aa" "bb" "cc" "n")
lst2 '(("1" . "V1")("2" . "V2")("3" . "V3")("4" . "V4"))
--->
(("1" . "aa")("2" . "bb")("3" . "cc")("4" . "n"))
thankyou
-
Maybe;
(mapcar '(lambda ( a b ) (cons (car a) b)) lst2 lst1)
-
Thankyou Lee
This is perfect.
I had tried a few combinations and some are very close to yours.
One thing im keep thinking is the (cdr (assoc of the lst2.
Your one liner give me great insight of trying to understand the code.
-
You're welcome jaydee :-)
If you have any questions about the methods or code, just ask.
-
Now i got another issue convert mtext paragraph string with enter return on each line
("Abc\\pefg\\pPPP")
--->
("abc" "efg" "PPP")
thanks
-
Perhaps take a look at this (http://lee-mac.com/stringtolist.html) :-)
-
Maybe this:
; parser by CAB multi char delim, match "xyz"
(defun sparser (str delim / dlen ptr lst)
(setq dlen (1+ (strlen delim)))
(while (setq ptr (vl-string-search delim str))
(setq lst (cons (substr str 1 ptr) lst))
(setq str (substr str (+ ptr dlen)))
)
(reverse(cons str lst))
)
(sparser "Abc\\pefg\\pPPP" "\\p")
("Abc" "efg" "PPP")
-
Oh, sorry Lee I should have looked at the link. We have the same answer. :oops:
-
Thankyou Cab and Lee
Another perfect answers.
-
Oh, sorry Lee I should have looked at the link. We have the same answer. :oops:
No worries Alan, the more the merrier 8-)
-
Hi Lee and Cab
How to get around a string that looks like this
"
DBA\P1
AAA
BBB
CCC
"
(setq lst '("DBA\\\\P1\\PAAA\\PBBB\\PCCC"))
(sparser lst "\\P")
===>
("DBA\\" "1" "AAA" "BBB" "CCC")
(LM:str->lst lst "\\P")
===>
("DBA\\" "1" "AAA" "BBB" "CCC")
prefer result
("DBA\P1" "AAA" "BBB" "CCC")
Thankyou
-
Refer to my previous post.
Just relise its a sticky issue.
The stripmtext3.5 could not do it.
Xpress tool text2mtext could not do it.
My way of getting around the "\P" in the string is do a find and replace \P to /P before using the program.
Thankyou
-
This is almost the correct result except the double \\ should be a single \
You would need to replace \\ with \ to finish the job.
(setq lst '("DBA\\\\P1\\PAAA\\PBBB\\PCCC"))
(sparser lst "\\P")
===>
("DBA\\" "1" "AAA" "BBB" "CCC")
-
The stripmtext3.5 could not do it.
Xpress tool text2mtext could not do it.
Unformat String (http://lee-mac.com/unformatstring.html) can do it 8-)
_$ (LM:Unformat "DBA\\\\P1\\PAAA\\PBBB\\PCCC" nil)
"DBA\\P1 AAA BBB CCC"
-
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\
-
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?
-
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
-
OK, I get it now :-o
Off to get more coffee......
-
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"
-
How about this instead:
(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):
_$ (MultilineParser "DBA\\\\P1\\PAAA\\PBBB\\PCCC")
("DBA\\P1" "AAA" "BBB" "CCC")
-
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:
C:\Computer\LISP
Now use the TXT2MTXT Express Tools function on that DText. :wink:
I describe this behaviour in more detail here (http://lee-mac.com/gettruecontent.html).
-
Thankyou Lee for your help
I admit i dont come across formatted mtext codes use as actual text content, but i rather be safe.
-
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: