broncos15 Posted December 15, 2016 Share Posted December 15, 2016 So I have already created a routine that will insert a keynote table with a certain numerical block in the each row of the 1st column. For example, a 4 row table with 4 square blocks numbered 1-4. This routine is awesome to use when first starting projects, the issue is on past projects that someone instead used mtext. What I am wanting to do is to convert this mtext into a table. Once I can extract each line of the mtext I am fine with the code, but I'm having issues with how to handle the information. The text string might read when dumping the text string "[url="file://\\A1;\\pxt30;PROPOSED"]\\A1;\\pxt30;PROPOSED[/url] USE A TABLE\\P\\PPROPOSED TABLE\\P\\THIS IS AN EXAMPLE" . I want to extract the text and insert it into column 2 of my table, where \\P\\ is what differentiates what would be in each column. To do this I have a few questions 1)How can I find the #of \\P\\ in the text (that way I can make a table with +1 that amount of rows). 2) How can I copy what is just between the \\p\\ so that each row in column 2 reads that information. In this example, I would have row 1: PROPOSED USE A TABLE, row 2:PPROPOSED TABLE, and row 3: THIS IS AN EXAMPLE. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 16, 2016 Share Posted December 16, 2016 The one you want is a Vl command and it returns the starting character, will try to find. from helppattern is not found; the first character of the string is position 0. Examples (vl-string-search "foo" "pfooyey on you") 1 (vl-string-search "who" "pfooyey on you") nil (vl-string-search "foo" "fooey-more-fooey" 1) 11 ; note problem with p & P need to strcase it so always P (setq str "[url="file://\\A1;\\pxt30;PROPOSED"]\\A1;\\pxt30;PROPOSED[/url] USE A TABLE\\P\\PPROPOSED TABLE\\P\\THIS IS AN EXAMPLE") Command: (vl-string-search "[url="file://\\p"]\\p[/url]" str) 4 Command: (vl-string-search "[url="file://\\P"]\\P[/url]" str 7) 31 Quote Link to comment Share on other sites More sharing options...
broncos15 Posted December 16, 2016 Author Share Posted December 16, 2016 The one you want is a Vl command and it returns the starting character, will try to find. ; note problem with p & P need to strcase it so always P (setq str "[url="file://\\A1;\\pxt30;PROPOSED"]\\A1;\\pxt30;PROPOSED[/url] USE A TABLE\\P\\PPROPOSED TABLE\\P\\THIS IS AN EXAMPLE") Command: (vl-string-search "[url="file://\\p"]\\p[/url]" str) 4 Command: (vl-string-search "[url="file://\\P"]\\P[/url]" str 7) 31 BigAl, thank you so much for the help! So when I am testing it on an mtext object that has 5 \\P\\, it only returns the first one. Code (setq info (vl-string-search "[url="file://\\P\\"]\\P\\[/url]" (vla-get-textstring obj))) . How can I find the location of every paragraph/empty space? Quote Link to comment Share on other sites More sharing options...
Roy_043 Posted December 16, 2016 Share Posted December 16, 2016 Here is a string split function that may help: ; Based on code by Luis Esquivel. See: https://www.theswamp.org/index.php?topic=7272.msg90039#msg90039 ; (KGA_String_Split "aabbaaccaa" "aa" nil) => ("" "bb" "cc" "") ; (KGA_String_Split "aabbaaccaa" "AA" nil) => ("aabbaaccaa") ; (KGA_String_Split "aabbaaccaa" "AA" T) => ("" "bb" "cc" "") ; (KGA_String_Split "aabbaaccaa" "" nil) => nil (defun KGA_String_Split (str sub ignoreCaseP / i j len lst srchStr) (if (/= 0 (setq len (strlen sub))) (progn (if ignoreCaseP (progn (setq srchStr (strcase str)) (setq sub (strcase sub)) ) (setq srchStr str) ) (setq i 0) (while (setq j (vl-string-search sub srchStr i)) (setq lst (cons (substr str (1+ i) (- j i)) lst)) (setq i (+ j len)) ) (reverse (cons (substr str (1+ i)) lst)) ) ) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 16, 2016 Share Posted December 16, 2016 If you look at the command check the help I did not mention that you can imply a start position in the string (vl-string-search "\\p" str startposition) so (vl-string-search "\\p" str) start at very first character note help this is 0 but if left out starts at beginning. find 1st \\p returns 4 use substr to make a list so (vl-string-search "\\p" str 6) use substr & cons to add to list a 2nd line so (vl-string-search "\\p" str 33) use substr & cons to add to list a 3rd line keep repeating till no more Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.