octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #51707] textscan seems to skip chunks of text


From: Kai Torben Ohlhus
Subject: [Octave-bug-tracker] [bug #51707] textscan seems to skip chunks of text
Date: Thu, 24 Aug 2017 17:14:54 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36

Follow-up Comment #3, bug #51707 (project octave):

Be aware, that `textscan` "eats" empty lines, leading and trainling spaces! 
That makes the difference in the line count.  It is not documented, but
`textscan` is intended to read formatted lines (not empty data lines).  Three
alternatives are given below.  To check the difference I just wrote out what
Octave read and compared the files using a diff tool of your choice.


filename='HB_SNG3.html';
if ~exist(filename,'file')
  %download file
 
url='http://web.archive.org/web/20170807165834/https://www.bible.com/nl/bible/75/SNG.3.htb';
  urlwrite(url,filename);
end

fid=fopen(filename,'r');
data=textscan(fid,'%s\n','Delimiter','\n');
fclose(fid);
data = data{1};
length(data) # 1110/1137

# Write out what you read to diff the files
unlink([filename "_2"]);
fid=fopen([filename "_2"],'w');
fprintf (fid, "%s\n", data'{:});
fclose(fid);

# Alternative A
data = importdata (filename, "\n");
length(data) # 1115/1137

# Alternative B
data = fileread (filename);
data = strsplit (data, "\n");
length(data) # 1116/1137

# Alternative C from the `publish` function
#
https://hg.savannah.gnu.org/hgweb/octave/file/e54e13ee99ce/scripts/general/publish.m#l700
data = cell();
fid = fopen (filename, "r");
i = 0;
do
  data{++i} = fgetl (fid);
until (! ischar (data{i}))
fclose (fid);
data = data(1:end-1);  # No EOL
length(data) # 1110/1137


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?51707>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]