Posted By

magicrebirth on 02/12/10


Tagged

String scheme impromptu


Versions (?)

scheme: replace a string


 / Published in: Scheme
 

Written for the impromptu-scheme environment.. other schemes might need different procedures..

  1. (define string-replace
  2. (lambda (s match replacement)
  3. (let ((ll (string->list s))
  4. (match1 (char match))
  5. (replacement1 (char replacement)))
  6. (if (= (string-length match) 1)
  7. (let ((z (map (lambda (x)
  8. (if (equal? x match1)
  9. replacement1
  10. x))
  11. ll)))
  12. (list->string (list-flatten z)))
  13. ;z)
  14. (print "i can match only single characters for now")))))

Report this snippet  

You need to login to post a comment.