Home
Insert
Update snippet 'Lazily split string'
Title
Description
Splits strings lazily, instead of splitting entire string into an array like System.String.Split. Especially useful for very large strings.
Source code
module String = let split (sep:string) (str:string) = match sep, str with | ((null | ""), _) | (_, (null | "")) -> seq [str] | _ -> let n, j = str.Length, sep.Length let rec loop p = seq { if p < n then let i = match str.IndexOf(sep, p) with -1 -> n | i -> i yield str.Substring(p, i - p) yield! loop (i + j) } loop 0
Tags
parsing
strings
parsing
strings
Author
Link
Reference NuGet packages
If your snippet has external dependencies, enter the names of NuGet packages to reference, separated by a comma (
#r
directives are not required).
Update