Question
· Sep 21, 2016

How to open ms-dos text files

Hi, There

How to use open text file. I have a one file. the file is original file from excels file. After later convert to CSV file.

some cells has include cr+lf  control code. If i open and use from cache. reding time,Cache was wrong line feed point.

how do i edit my source code?

==============================================

s infile="c:\csvfile.csv"

o infile:"r"

1 u infile r line i $zeof<0 c infile q

   f i=1:1:10 s wd(i)=$p(line,",",i)

g 1

==============================================

Discussion (4)0
Log in or sign up to continue

Please forget about old-way programming. We now have so many features out-of-the-box which helps write understandable code quite easy.

set fs=##class(%Stream.FileCharacter).%New()
set fs.Filename="c:\csvfile.csv"
while 'fs.AtEnd {
  set line=$listfromstring(fs.ReadLine(), ",")

  #; in line you will get listbuild for all columns in a row
​}

class %Stream.FileCharacter helps to read text files, which may contain text in different codepages, and line ends.

Or if you need to read some binary data, which should have some conversion on the fly, use %Stream.FileBinary.