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<charleshi...@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



_________________________________________________
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users

Reply via email to