Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. ;----------STRING-TRIM----------------
  2. (define (str-tr-l x)
  3. (if (or (equal? (car x) #\tab) (equal? (car x) #\newline) (equal? (car x) #\space))
  4. (str-tr-l (cdr x))
  5. (list->string x)))
  6. (define (str-tr-r x)
  7. (if (or (equal? (car x) #\tab) (equal? (car x) #\newline) (equal? (car x) #\space))
  8. (str-tr-r (cdr x))
  9. (list->string (reverse x))))
  10.  
  11. (define (string-trim-left xs)
  12. (str-tr-l (string->list xs)))
  13.  
  14. (define (string-trim-right xs)
  15. (str-tr-r (reverse (string->list xs))))
  16.  
  17. (define (string-trim xs)
  18. (string-trim-right (string-trim-left xs)))
  19.  
  20. ;---------STRING-***FIX---------------------
  21.  
  22. (define (str-pr-sf x y)
  23. (if (not (null? x))
  24. (if (equal? (car x) (car y))
  25. (str-pr-sf (cdr x) (cdr y))
  26. (equal? (car x) (cdr y)))
  27. (null? x)))
  28.  
  29. (define (string-prefix? xs ys)
  30. (str-pr-sf (string->list xs) (string->list ys)))
  31.  
  32. (define (string-suffix? xs ys)
  33. (str-pr-sf (reverse (string->list xs)) (reverse (string->list ys))))
  34.  
  35. (define (str-in x y)
  36. (if (null? y)
  37. (not (null? y))
  38. (if (str-pr-sf x y)
  39. (str-pr-sf x y)
  40. (str-in x (cdr y)))))
  41.  
  42. (define (string-infix? xs ys)
  43. (str-in (string->list xs) (string->list ys)))
  44.  
  45. ;------------STRING-SPLIT---------
  46. (define (my-element? x xs)
  47. (if (not (null? xs))
  48. (if (equal? x (car xs))
  49. (equal? x (car xs))
  50. (my-element? x (cdr xs)))
  51. (not (null? xs))))
  52. (define (difference xs ys)
  53. (if (null? xs)
  54. '()
  55. (if (my-element? (car xs) ys)
  56. (difference (cdr xs) ys)
  57. (cons (car xs) (difference (cdr xs) ys)))))
  58.  
  59. (define (str-spl x)
  60. (if (null? x)
  61. '()
  62. (cons (list->string (cons (car x) '())) (str-spl (cdr x)))))
  63.  
  64. (define (string-split xs ys)
  65. (if (equal? (difference (string->list xs) (string->list ys)) (string->list xs))
  66. (cons xs '())
  67. (str-spl (difference (string->list xs) (string->list ys)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement