[plt-scheme] Checking if strings are only whitespace

From: Doug Orleans (dougorleans at gmail.com)
Date: Sun Mar 19 10:18:15 EST 2006

Robby Findler writes:
 > At Sun, 19 Mar 2006 12:26:28 +0100, Hans Oesterholt-Dijkema wrote:
 > > Dear All,
 > > 
 > > I'm looking fot the fastest way of checking if a string only consists
 > > of whitespace. 

Funny, I just did this last night.  (I wanted a version of
eliminate-whitespace for XML that preserves non-empty strings

 > These both seem to be faster and the second is faster than the first:
 > (define (is-space? str)
 >   (andmap char-whitespace? (string->list str)))
 > (define (is-space? x) (regexp-match #rx"^[ \t\n]*$" x))

This is somewhere in between in speed, but clearer:

(require (lib "string.ss" "srfi" "13"))

(define (is-space? x)
  (string-every char-whitespace? x))

--dougorleans at gmail.com

Posted on the users mailing list.