Created
April 29, 2011 22:42
-
-
Save tautologico/949169 to your computer and use it in GitHub Desktop.
Split a string into a list of string by breaking "words" separated by spaces
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
let split s = | |
let l = String.length s in | |
let rec whitespace i = | |
if i >= l then [] else | |
if s.[i] = ' ' then whitespace (i+1) else nonws i 1 | |
and nonws i j = | |
if (i+j) = l then [(i,j)] else | |
if s.[i+j] = ' ' then (i,j) :: whitespace (i+j) else nonws i (j+1) in | |
List.map (fun (i, l) -> String.sub s i l) (whitespace 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment