Skip to content

Instantly share code, notes, and snippets.

@esehara
Last active September 14, 2015 16:51
Show Gist options
  • Save esehara/b19af99f2a99d2966681 to your computer and use it in GitHub Desktop.
Save esehara/b19af99f2a99d2966681 to your computer and use it in GitHub Desktop.
CodeIQとかで"module Str"を使ったsplitが使えないので、自前で何とかsplitするやつを書く ref: http://qiita.com/esehara@github/items/894d8dd824b1354752f5
Str.split (Str.regexp_string ",") line
let string_separate s c =
let rec s_separate s c p =
let next_separate s p c =
try
(String.index_from s (p + 1) c)
with _ -> String.length s in
let start = p in
let next = next_separate s p c in
[String.sub s start (next - start)] @
(if next < String.length s then s_separate s c (next + 1)
else []) in
s_separate s c 0;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment