Hi,<div><br></div><div>Usually there are homework problems and stuff for tweaking strings but I was just playing around for the fun of it. I wondered what is the "best way" to do a couple of simple tasks but without regex. Here are two of them. They are not optimized I just wrote them in a way that seemed the simplest. What is a better way or different way?</div>
<div><br></div><div><div>#lang racket</div><div><br></div><div>(require rackunit)</div><div><br></div><div>;; string -> string</div><div>;; Removes vowels from the input</div><div>(define remove-vowels</div><div>  (lambda (word)</div>
<div>    (let ((test (lambda (c) (not (member c (list #\a #\e #\i #\o #\u)))))</div><div>          (ls (string->list word)))</div><div>      (list->string (filter test ls)))))</div><div><br></div><div>(check-equal? (remove-vowels "") "")</div>
<div>(check-equal? (remove-vowels "f") "f")</div><div>(check-equal? (remove-vowels "a e i o u") "    ")</div><div><br></div><div>;; string -> string</div><div>;; Replaces spaces in the input with dashes</div>
<div>(define replace-spaces</div><div> (lambda (word)</div><div>   (let ((test (lambda (c) (if (equal? c #\space) #\- c)))</div><div>         (ls (string->list word)))</div><div>     (list->string (map test ls)))))</div>
<div><br></div><div>(check-equal? (replace-spaces "") "")</div><div>(check-equal? (replace-spaces " ") "-")</div><div>(check-equal? (replace-spaces "a b c") "a-b-c")</div>
</div><div><br></div>