[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: newline comparison?
Matthew Flatt <mflatt@cs.utah.edu> writes:
> > ([string=? line "\n"] (do-something)))
>
> What would work in version 199.X (the upcoming release, available only
> through CVS), but not 103.X.
That's really an improvement! Is 199.X stable? Somewhat stable? :)
> > ([equal? (string-ref line 0) #\newline]
> > ([eq? string-ref line 0) #\newline] (do-something)))
>
> Those should work.
I think that these failed because it was a \r\n combination, and the
read-line was leaving the #\return, which I mistook for a newline. (I
was thinking this while driving home from work, but after I posted.)
> But I think the problem may be here:
>
> > (let ([line (read-line input)]) ;; assume this reads in a newline only
>
> `read-line' strips off the newline character, so a line containing
> nothing will produce the empty string.
The 'any mode would fix then, and then I could compare for an empty
string, like this:
(string=? "" line)
> Beware of variying newline conventions. For example, when reading a
> DOS/Windows file, you'll get both #\newline and #\return from the port
> (and `read-line' will return the #\return characters) unless it's opened
> in 'text mode.
Thanks. :) I'm guessing this was it.
--
Chris