Read-line before or after a comma

Read-line before or after a comma

Jonathan3891
Advisor Advisor
423 Views
9 Replies
Message 1 of 10

Read-line before or after a comma

Jonathan3891
Advisor
Advisor

Is it possible to read a line in a text file before or after a comma?

 

For example:

Line 1 will have: TEST1,TOS %%script(Q = (%ObjectTopLevel): If Q>0 then appendstring ("+" & (FormatNumber(Q,3))) else appendstring (FormatNumber(Q,3)))

 

But the list box will only show: TOS %%script(Q = (%ObjectTopLevel): If Q>0 then appendstring ("+" & (FormatNumber(Q,3))) else appendstring (FormatNumber(Q,3)))

 

My current code segment to read a file:

 

 

  (setq LC nil)
  (setq OpenFile (open (findfile "LabelContent.cfg")"R"))
  (while (setq line (read-line OpenFile))
    (setq LC (cons line LC))
    );while
  (setq LC (reverse LC))
  (close OpenFile)
  (dcl-ListBox-AddList LabelContent/Form1/ListBox1 LC)

 

 


Jonathan Norton
Blog | Linkedin
0 Likes
Accepted solutions (2)
424 Views
9 Replies
Replies (9)
Message 2 of 10

ВeekeeCZ
Consultant
Consultant

Why? Just split it afterward.

0 Likes
Message 3 of 10

Jonathan3891
Advisor
Advisor
I'm building a dcl that contains vbscript's for Advance Steel.

The text before the comment is meant to be a description of the script.

I do not know how to split it afterward.

Jonathan Norton
Blog | Linkedin
0 Likes
Message 4 of 10

ВeekeeCZ
Consultant
Consultant
Accepted solution

Seems too simple, I must be missing something... 

 

(setq lc2 (mapcar '(lambda (x) (substr x (+ 2 (vl-string-search "," x)))) lc))
(dcl-ListBox-AddList LabelContent/Form1/ListBox1 LC2)

0 Likes
Message 5 of 10

Jonathan3891
Advisor
Advisor
Thank you @ВeekeeCZ. I'm only a novice code writer.

I'm sure it's simple, but how do I read only the string before the comma?

Jonathan Norton
Blog | Linkedin
0 Likes
Message 6 of 10

ВeekeeCZ
Consultant
Consultant
Accepted solution

(setq lc1 (mapcar '(lambda (x) (substr x 1 (vl-string-search "," x))) lc))

0 Likes
Message 7 of 10

Jonathan3891
Advisor
Advisor

Thank you @ВeekeeCZ!


Jonathan Norton
Blog | Linkedin
0 Likes
Message 8 of 10

ВeekeeCZ
Consultant
Consultant

BTW that posted code search for 1st comma in the line. But you have multiple commas there -- so it presumes that you have this comment at the beginning of each line (if there are more lines in the file).

0 Likes
Message 9 of 10

Jonathan3891
Advisor
Advisor
The first comma is all I needed. The rest is part of the VBScript.

Jonathan Norton
Blog | Linkedin
0 Likes
Message 10 of 10

Jonathan3891
Advisor
Advisor

Here is what it looks like so far.

Jonathan3891_0-1661287066567.png

 


Jonathan Norton
Blog | Linkedin