Jump to content

Remove string from item of list


reza

Recommended Posts

Hi everyone:

I have a list like this:

 

(" 1 -30.0000 1158.3733 1" " 25 -29.7469 1158.5000 1" " 138 -29.3861 1158.6920 1")

 

How can I convert it to the following?

 

("-30.0000 1158.3733" "-29.7469 1158.5000" "-29.3861 1158.6920")

 

Thanks if you guide me

Link to comment
Share on other sites

I think the list came from an external file [csv/txt]., What you need to do is separate the individual items before passing the values to a list.

Show us the code that you use to build the list and we'll pick up from there.

Link to comment
Share on other sites

thanks a lot

sure

 

What are you planning to do with the converted list? Do you need this a point list?

converted to floating point rather than strings? did you write those code yourself?

Link to comment
Share on other sites

I do lots of things with points as a Civil engineer and like Pbe what is the bottom line of the desired ouput. It is feasible to pull apart the txt files from scratch and make your list of points directly.

Link to comment
Share on other sites

I need this list to send use in a program called "CSDP"

 

But this question is important to me in this regard

How to solve this problem with the Lisp or Visual Lisp instructions

Regardless of what software is used in this information.

 

I wrote the first application using a post in one of the forums.

And the second program using the functions available in Lisp.

Link to comment
Share on other sites

From a recent thread

 

Modified for your requirement

 

(defun _csv->lst ( str / pos)
[color="blue"](setq str (vl-string-left-trim  " "  str))   [/color] 
(if (setq pos (vl-string-position [color="blue"]32[/color] str))
   (cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2)) [color="blue"]32[/color] ))
   (list str)
   )
)

 

resulting to

 

("1" "-30.0000" "1158.3733" "1") ("2" "-29.7469" "1158.5000" "1") ("3" "-29.3861" "1158.6920" "1") ....

 

 (strcat (cadr x) " " (caddr x)) 

Link to comment
Share on other sites

Starting with the original text file makes more sense to me and just save a new text file with exactly what you want. Dont make un-necessary lists. The text file has patterns so its not that hard. This coding could be written in any programming language even write it in excel it has VBA built in.

 

What is "CSDP"

 

1 read line look for "Station" store line

2 continue reading look for "vertex"

3 read sequence of lines when blank is end of xsection.

 

Repeat reading lines with steps 1 2 3.

 

Last word opened in Excel and just copied and pasted to achieve result required no sweaty brow trying to write code just import using space as delimiter. Again make a macro to delete lines not required.

Link to comment
Share on other sites

Hi pBe

Thank you

Your advice helped me solve my problem very much

 

Good for you, Like what BIGAL said, the process can be streamlined by starting with the original text file.

 

Have fun coding.

 

pBe

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...