octave-maintainers
[Top][All Lists]
Advanced

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

Re: Improving strread / textread / textscan


From: Ben Abbott
Subject: Re: Improving strread / textread / textscan
Date: Mon, 31 Oct 2011 19:17:49 -0400

On Oct 31, 2011, at 4:54 PM, PhilipNienhuis wrote:

> <Example 7>
>>> str = sprintf ('aaaaa\nbbbbb');
>>> c = textscan (str, '%s', 'endofline', '');
>>> c{:}
> ans = 
>    'aaaaa
> bbbbb'
> 
> <Example 8>
>>> c = textscan (str, '%s', 'endofline', '\n');
>>> c{:}
> ans = 
>    'aaaa'
>    'bbb'
> 
> (...Hey... where did that one 'b' go...? this happens consistently in
> r2007a)

Note, that there are two "b"s missing, and one "a" missing.

TMW has fixed this bug. With R2011b

c = textscan (str, '%s', 'endofline', '');
strcat ('"', c{1}{1}, '"')

ans =

"aaaaa
bbbbb"

c = textscan (str, '%s', 'endofline', '\n');
strcat ('"', c{1}{1}, '"')

ans =

"aaaaa"

strcat ('"', c{1}{2}, '"')

ans =

"bbbbb"


> As you can see in example 6, this is not what happens. At least the trailing
> space is preserved.
> 
> Anyway, ML seems to have a consistent (but obscurely documented) rule about
> parsing numeric versus string fields depending on delimiter/whitespace
> values. That might render implementing it in Octave a bit easier.
> 
> Philip

Good catch. So, for delimited character fields, the leading whitespace is 
trimmed and the trailing whitespace is preserved.

Ben



reply via email to

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