Reading from file

andrew_simi

New Member
The file is read by the lines. Each line is a list of elements where delimiter is "," (comma).
Problem is that for example on 5th place can be character value with "" (semicolon) with comma inside
i.e. line = ,,,,"abc,def,g|hi|||",

the problem is that i can not read

Code:
entry(5, entry(1,line,","), "|")

is any way to read that field?
 

TomBascom

Curmudgeon
I don't see any semi-colons.

You need to show a bit more of you code to get a good answer. I would code something like this:

Code:
define variable i as integer no-undo.
define variable v as character no-undo extent 16.

input from textFile.dat.
repeat:

  import delimiter "," v.
  display v. /* or do whatever it is that should be done with the imported values... */

  do i = 1 to 16:
    if num-entries( v[i], "|" ) > 1 then . /* do something with an element that contains more elements... */
  end.

end.
 

andrew_simi

New Member
Main semi-colons is "," - sub-semi-colon is "|".

From line:
Code:
,,,,"abc,def,g|hi|||",
I want to get abc,def,g

Comma "," is a delimiter. So basically this char is reserved. It can not appear in any element of list.
But i have 1 element where this comma is placed. The "|" are separators inside element of list which give annother list.

So if I do
Code:
 import delimiter "," v.
it gives me more elements what I expect.
 

TomBascom

Curmudgeon
I'm sorry but your requirements aren't making any sense to me and seem to conflict with one another.
 

Cecil

19+ years progress programming and still learning.
I think I understand your problem and here is KB (P112126):

Status: Unverified

GOAL:

How to import a CSV file which contains commas in the data ?

GOAL:

Importing a CVS file with commas within the data

FIX:


This code only provides a way to separate the entries of the record
string ,
additional customization has to be performed to load the data to the
indicated records.
This code assumes that the format of the datafile.csv has the
following format :
"12345","abcdef","56789","ghi, jklmn","031415"
"12345","abcdef","56789","abc, defg","031415"
"12345","abcdef","56789","zxy, abcd","031415"

Code :
Code:
DEF VAR myRow AS CHAR.
DEF VAR i AS INTEGER.

INPUT FROM "datafile.csv".
REPEAT:
  IMPORT UNFORMATTED myRow.
  getEntries(myRow).
END.
FUNCTION getEntries RETURN CHAR (INPUT theStr AS CHAR):
   REPEAT i = 2 to NUM-ENTRIES(theStr, '"') BY 2:
    MESSAGE ENTRY(i,theStr,'"') VIEW-AS ALERT-BOX /* Here we get each
different entry from the line, 
                                                                      
                this can be stored in a variable and then assigned to
a field */
  END.
END
 
Top