Last active
September 28, 2015 14:48
-
-
Save meijeru/2070c3acf8c1971e99bd to your computer and use it in GitHub Desktop.
Red mezzanine function to split a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Red [ | |
Title: "Split mezzanine" | |
Purpose: {split a string} | |
Author: "Rudolf W. MEIJER" | |
File: %split.red | |
Version: "0.0.0" | |
Date: "10-May-2015" | |
Rights: "(c) Copyright 2015 Rudolf W. MEIJER" | |
License: "TBD" ; source license (URL or full text) | |
] | |
;---|----1----|----2----|----3----|----4----|----5----|----6----|----7----|- | |
split: func [ | |
"splits a string into a block of strings, at the specified separator(s)" | |
s [string!] "string to be split" | |
c [char! string!] "separator, may be multi-character" | |
return: [block!] | |
/local res p l | |
][ | |
l: either char? c [1][length? c] ; compute length of separator | |
res: copy [] ; allocate result | |
if l > 0 [ | |
while [p: find/case s c][ | |
insert tail res copy/part s p | |
s: skip p l | |
] | |
] | |
insert tail res copy s ; store last (or only) part | |
res | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment