[racket] newbie string handling problem

From: Charles Hixson (charleshixsn at earthlink.net)
Date: Fri Apr 1 01:03:44 EDT 2011

Thanks.  Regular expressions *isn't* what I wanted.  (When I've tried 
them before [in Python] they made Python seem fast.)

On 03/31/2011 05:06 PM, Thomas Chust wrote:
> 2011/4/1 Charles Hixson<charleshixsn at earthlink.net>:
>    
>> [...]
>> 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,
>> [...]
>>      
> Hello,
>
> well, you can do the same in Racket — just searching for "trim" in the
> documentation would have shown you where to find the necessary
> functions:
>
>    #lang racket/base
>    (require
>     srfi/13)
>
>    (provide
>     (all-defined-out))
>
>    (define (ends-with-colon? str)
>      (string-suffix? ":" (string-trim-right str)))
>
> You could also use a regular expression:
>
>    #lang racket/base
>    (provide
>     (all-defined-out))
>
>    (define (ends-with-colon? str)
>      (regexp-match? #px":\\s*$" str))
>
> By the way, this solution would probably be the more efficient in
> Python, as well:
>
>    import re
>
>    def ends_with_colon(str):
>      return re.search(':\s*$', str)<>  None
>
> I hope that helps :-)
>
> Ciao,
> Thomas
>
>
>    



Posted on the users mailing list.