[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
newline comparison?
I hope this isn't a stupid question, but I'm having trouble getting a
very simple operation to work.
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?"
I have tried many things to make the above comparison, none work.
Below is an assortment of some of types of "cond" questions I've tried
asking, but none are able to detect that a string is just a newline.
This is so easy in C++, but I've searched and searched the help to no
avail. I've seen very scant documentation on string handling in
scheme. Most books cover recursion and other more interesting
programming topics. But string manipulation is very important to me,
and it seems to be very largely glossed over in almost every context.
I was hoping that was because it was easy. :)
Here's my code:
(let ([line (read-line input)]) ;; assume this reads in a newline only
(cond ([string=? line "~n"] (do-something)))
([string=? line "\n"] (do-something)))
([string=? line "#\n"] (do-something)))
([string=? line "#\newline"] (do-something)))
([equal? (string-ref line 0) #\newline]
([eq? string-ref line 0) #\newline] (do-something)))
([string=? line "
"] (do-something)))
There must be something I'm overlooking, but this seems ridiculously
difficult or maybe just underdocumented. None of the above tests
work, and I'm kind of unsure how to figure this out.
Sorry for such a newbie question, but I've spent at least an hour
experimenting with it without success.
Thanks!
--
Chris