Anonymous user
Tokenize a string: Difference between revisions
→{{header|OCaml}}
(Added Oz example.) |
|||
Line 576:
Or the [[:Category:Recursion|tail-recursive]] equivalent:
<lang ocaml>
so we externalise it in a sub-function *)
let string_index str c =
with Not_found -> None
let split_char sep str =
let rec aux acc str =
match string_index str sep with
| Some i ->
▲ let i = String.index str sep in
let this = String.sub str 0 i
and next = String.sub str (i+1) (String.length str - i - 1) in
aux (this::acc) next
List.rev(str::acc)
in
aux [] str
|