[racket] newbie string handling problem

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Thu Mar 31 19:44:12 EDT 2011

On Thu, Mar 31, 2011 at 7:38 PM, Charles Hixson
<charleshixsn at earthlink.net> wrote:
> Hi,
> I'm trying to determine whether the last non-whitespace character of a
> string is a colon, and I haven't been able to figure out the best way of
> doing this.  In python I'd just trim the string and look at the character
> before the end, but while Racket seems to have a string-length function, it
> doesn't seem to have anything analogous to trim.  So how should it be done?
>
> The best I've come up with is to explode the string into a list of
> characters, and handle it that way, but that's clearly quite wasteful of
> both processing and RAM.  (Of course, part of it is that the best way I've
> figured to proceed from there is to then copy that list to another list
> checking at each step of the way to tell if I was done, and then if it was
> successful to join the resultant list back into a string.)

Charles,

See the documentation on regular expressions.

http://docs.racket-lang.org/reference/regexp.html

--Carl



Posted on the users mailing list.