; split1.scm - split a delimited string into substrings
(define (string-split str char)
(string-split-2 '() '() (reverse (string->list str)) char))
;if equals delimiter character: add acummulated to split, drop delimiter, move on to next char
(define (string-split-2 split acum rem char)
;(display (format "~%split:~A, acum:~A, rem:~A, char:~A" split acum rem char))
(cond
((null? rem) (cons (list->string acum) split))
((char=? (car rem) char)
(string-split-2 (cons (list->string acum) split) '() (cdr rem) char) )
(else
(string-split-2 split (cons (car rem) acum) (cdr rem) char) ) ))
(string-split "hello:world:goodbye" #\:)
(string-split ":hello:world:goodbye" #\:)
(string-split "hello:world:goodbye:" #\:)
(define pswd-file-line "wandy:3xuncWdpKhR.:73:22:Wandy Saetan:/usr/wandy:/bin/csh")
(string-split pswd-file-line #\:)
;-------------------------------------------------------------------------------
; output:
;("hello" "world" "goodbye")
;("" "hello" "world" "goodbye")
;("hello" "world" "goodbye" "")
;("wandy" "3xuncWdpKhR." "73" "22" "Wandy Saetan" "/usr/wandy" "/bin/csh") Text file Source (historic): geocities.com/soho/square/3472
geocities.com/soho/squaregeocities.com/soho
(to report bad content: archivehelp @ gmail)
|
|
|
|
|