Jump to content

Parsing comma delimited file


Hudson

Recommended Posts

Good morning,

 

Now that I can write my comma delimited file I'd like to load it.

 

I've searched around, but haven't turned anything up that readily makes sense of what I want.. which surprises me.

 

Right now my delimiter is a , with no space on either side.. does that make it easier or harder?

 

I know there is some sort of command for reading a string character by character.. but haven't located it as of yet.

 

Thanks for any and all help,

 

Andrew

Link to comment
Share on other sites

What is the final form you wish for the output the string is being converted to:

 

    point list
    plain list
    dotted pair
    another string
    something that can be evaluated

 

Each has to be dealt with differently. -David

Link to comment
Share on other sites

Mr. Gile was nice enough to post these one time...

;;; STR2LST
;;; Transforms a string with separator into a list of strings
;;; Author: Gile
;;; Arguments
;;; str = the string
;;; sep = the separator pattern
(defun str2lst (str sep / pos)
 (if (setq pos (vl-string-search sep str))
   (cons (substr str 1 pos)
     (str2lst (substr str (+ (strlen sep) pos 1)) sep)
   )
   (list str)
 )
)

;;; lST2STR
;;; Returns a string which is the concatenation of a list and a  separator
;;; Author: Gile
;;; Arguments
;;; str = the string
;;; sep = the separator pattern
(defun lst2str (lst sep)
 (if (cadr lst)
   (strcat (vl-princ-to-string (car lst))
       sep
       (lst2str (cdr lst) sep)
   )
   (vl-princ-to-string (car lst))
 )
)

Link to comment
Share on other sites

Alan thanks!

 

That looks like exactly what I want, or close enough to it.

 

I want to read a line and turn it into a list of strings which will be a list of list of strings.

 

Andrew

Link to comment
Share on other sites

Alan thanks!

 

That looks like exactly what I want, or close enough to it.

 

I want to read a line and turn it into a list of strings which will be a list of list of strings.

 

Andrew

:) You can do exactly that with what I've posted.

(str2lst STRING ",")

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...