[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: newline comparison?
Quoting Chris Uzdavinis:
> Here's the situation: I have a string whose value is a single newline
> character. (The variable name is 'line'.) I want to ask in a
> (cond...) statement the question "is this string equal to the string
> containing just a newline?"
>
> [...]
>
> ([string=? line "\n"] (do-something)))
What would work in version 199.X (the upcoming release, available only
through CVS), but not 103.X.
> ([equal? (string-ref line 0) #\newline]
> ([eq? string-ref line 0) #\newline] (do-something)))
Those should work.
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.
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.
Matthew