read a line from csv from index 2 to the end of line

read a line from csv from index 2 to the end of line

ss6153
Enthusiast Enthusiast
424 Views
2 Replies
Message 1 of 3

read a line from csv from index 2 to the end of line

ss6153
Enthusiast
Enthusiast

Hello Reader
my question is in different parts so i am listing them out:


1) I have defined a function this way 

(defun test ( str1 x y text1 text2)                                                                            ---(a)

 

and then using this to insert

(command "_insert" str1 insertpt1 "" "" "" text1 text2)                                        ---(b)

 

I want to pass a list instead of text1,text2, where 'text' is a list of strings 
So if i am not wrong, I will modify (a) like this 

(defun test ( str1 x y text

 

How should I modify (b) ?

 

2) I am reading data from a csv file using Lee Mac's readcsv function 
After (setq data (LM:readcsv file)), I am accessing each line of the csv like this:

(foreach line data       ;; etc etc                                                                                  ---(c)

 

The csv looks something like this: 

"A",34,35,"B","C","D"

"AA",42,46

"AAA",29,54,"BB","CC","DD","EE","FF"

 

What I am aiming for is:

for every element in 'line' (reference to (c)) if the index of element is greater than 2 then append it to a list, say 'textlist'   [catering to corner case that list is empty]

How should go about doing that ?

 

3) Now I should be able to call the function test like this:

(test name (read p1) (read p2) textlist)                                      ; ignore name, p1,p2. already read from csv

 

Please help me...

0 Likes
425 Views
2 Replies
Replies (2)
Message 2 of 3

ВeekeeCZ
Consultant
Consultant

Ad 1 look into help for car, cadr, last functions.

Ad 2 use another Lee's function then see the help for the nth and append functions

http://www.lee-mac.com/stringtolist.html

0 Likes
Message 3 of 3

Sea-Haven
Mentor
Mentor

Like  it is sometimes easier to use Nth for long lists, (nth x lst) you just need to know that a nth starts at 0 not 1, (length lst) will tell you how many items are in a list so (> (length lst) 2) do something. You can use something like

 

(setq x 2) 
(repeat (- (length lst) 2)
(setq lst2 (cons (nth x lst) lst2)) ; or make a string here 
(setq x (1+ x))
)

 

0 Likes