2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,7 +1,2 @@
|
|||
let rec split_char sep str =
|
||||
try
|
||||
let i = String.index str sep in
|
||||
String.sub str 0 i ::
|
||||
split_char sep (String.sub str (i+1) (String.length str - i - 1))
|
||||
with Not_found ->
|
||||
[str]
|
||||
let words = String.split_on_char ',' "Hello,How,Are,You,Today" in
|
||||
String.concat "." words
|
||||
|
|
|
|||
|
|
@ -1,18 +1,10 @@
|
|||
(* [try .. with] structures break tail-recursion,
|
||||
so we externalise it in a sub-function *)
|
||||
let string_index str c =
|
||||
try Some(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 this = String.sub str 0 i
|
||||
and next = String.sub str (i+1) (String.length str - i - 1) in
|
||||
aux (this::acc) next
|
||||
| None ->
|
||||
List.rev(str::acc)
|
||||
in
|
||||
aux [] str
|
||||
;;
|
||||
let split_on_char sep s =
|
||||
let r = ref [] in
|
||||
let j = ref (String.length s) in
|
||||
for i = String.length s - 1 downto 0 do
|
||||
if s.[i] = sep then begin
|
||||
r := String.sub s (i + 1) (!j - i - 1) :: !r;
|
||||
j := i
|
||||
end
|
||||
done;
|
||||
String.sub s 0 !j :: !r
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue