Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (string-trim-left s)
- (define (iter i)
- (if (= i (string-length s))
- ""
- (if (or (char=? (string-ref s i) #\tab) (char=? (string-ref s i) #\space) (char=? (string-ref s i) #\newline))
- (iter (+ i 1))
- (substring s i)))
- )
- (iter 0))
- (define (string-trim-right s)
- (define (iter i)
- (if (= i (- 1))
- ""
- (if (or (char=? (string-ref s i) #\tab) (char=? (string-ref s i) #\space) (char=? (string-ref s i) #\newline))
- (iter (- i 1))
- (substring s 0 (+ i 1))))
- )
- (iter (- (string-length s) 1)))
- (define (string-trim s)
- (string-trim-left (string-trim-right s)))
- (define (string-prefix? a b)
- (if (> (string-length a) (string-length b))
- #f
- (string=? (substring b 0 (string-length a)) a)))
- (define (string-suffix? a b)
- (if (> (string-length a) (string-length b))
- #f
- (string=? (substring b (- (string-length b) (string-length a))) a)))
- (define (string-infix? a b)
- (define (iter a b)
- (if (> (string-length a) (string-length b))
- #f
- (if (string-prefix? a b)
- #t
- (iter a (substring b 1)))))
- (iter a b))
- (define (string-split str sep)
- (define (iter a b buf)
- (append
- (if (<= (string-length a) (string-length b))
- (if (string-prefix? a b)
- (list buf (iter a (substring b (string-length a)) ""))
- (list (iter a (substring b 1) (string-append buf (substring b 0 1)))))
- (list (string-append buf b))))
- )
- (define (my-flatten l)
- (if (null? l)
- '()
- (append (if (list? (car l))
- (my-flatten (car l))
- (list (car l)))
- (if (null? (cdr l))
- '()
- (my-flatten (cdr l)))
- ))
- )
- (my-flatten (iter sep str "")))
Advertisement
Add Comment
Please, Sign In to add comment