length s returns the length (number of characters) of the given string s.
val blit :
src:t->src_pos:int ->dst:Stdlib.Bytes.t ->dst_pos:int ->len:int ->
unit
blit ~src ~src_pos ~dst ~dst_pos ~len copies len characters from string src starting at character indice src_pos, to the Bytes sequence dst starting at character indice dst_pos. Like String.blit. Compatible with the -safe-string option.
replace ?which ~sub ~by s replaces some occurrences of sub by by in s.
parameterwhich
decides whether the occurrences to replace are:
`Left first occurrence from the left (beginning).
`Right first occurrence from the right (end).
`All all occurrences (default).
raisesInvalid_argument
if sub = "".
since 0.14
val is_sub :
sub:string ->sub_pos:int ->string ->pos:int ->sub_len:int ->
bool
is_sub ~sub ~sub_pos s ~pos ~sub_len returns true iff the substring of sub starting at position sub_pos and of length sub_len is a substring of s starting at position pos.
val repeat : string ->int -> string
repeat s n creates a string by repeating the string sn times.
val prefix : pre:string ->string -> bool
prefix ~pre s returns true iff pre is a prefix of s.
val suffix : suf:string ->string -> bool
suffix ~suf s returns true iff suf is a suffix of s.
since 0.7
val chop_prefix : pre:string ->string ->string option
chop_prefix ~pre s removes pre from s if pre really is a prefix of s, returns None otherwise.
since 0.17
val chop_suffix : suf:string ->string ->string option
chop_suffix ~suf s removes suf from s if suf really is a suffix of s, returns None otherwise.
since 0.17
val take : int ->string -> string
take n s keeps only the n first chars of s.
since 0.17
val drop : int ->string -> string
drop n s removes the n first chars of s.
since 0.17
val take_drop : int ->string -> string * string
take_drop n s is take n s, drop n s.
since 0.17
val lines : string ->string list
lines s returns a list of the lines of s (splits along '\n').
unlines_gen gen concatenates all strings of gen, separated with '\n'.
since 0.10
val set : string ->int ->char -> string
set s i c creates a new string which is a copy of s, except for index i, which becomes c.
raisesInvalid_argument
if i is an invalid index.
since 0.12
val iter : f:(char -> unit)->string -> unit
iter ~f s applies function f on each character of s. Alias to String.iter.
since 0.12
val filter_map : f:(char ->char option)->string -> string
filter_map ~f s calls (f a0) (f a1) … (f an) where a0 … an are the characters of s. It returns the string of characters ci such as f ai = Some ci (when f returns None, the corresponding element of s is discarded).
since 0.17
val filter : f:(char -> bool)->string -> string
filter ~f s discards characters of s not satisfying f.
since 0.17
val flat_map : ?sep:string ->f:(char -> string)->string -> string
flat_map ?sep ~f s maps each chars of s to a string, then concatenates them all.
parametersep
optional separator between each generated string.
since 0.12
val for_all : f:(char -> bool)->string -> bool
for_all ~f s is true iff all characters of s satisfy the predicate f.
since 0.12
val exists : f:(char -> bool)->string -> bool
exists ~f s is true iff some character of s satisfy the predicate f.
val split_on_char : by:char ->string ->string list
split_on_char ~by s splits the string s along the given char by.
since 1.2
val split : by:string ->string ->string list
split ~by s splits the string s along the given string by. Alias to Split.list_cpy.
since 1.2
Utils
val compare_versions : string ->string -> int
compare_versions s1 s2 compares version stringss1 and s2, considering that numbers are above text.
since 0.13
val compare_natural : string ->string -> int
compare_natural s1 s2 is the Natural Sort Order, comparing chunks of digits as natural numbers. https://en.wikipedia.org/wiki/Natural_sort_order
since 1.3
val edit_distance : ?cutoff:int ->string ->string -> int
edit_distance ?cutoff s1 s2 is the edition distance between the two strings s1 and s2. This satisfies the classical distance axioms: it is always positive, symmetric, and satisfies the formula distance s1 s2 + distance s2 s3 >= distance s1 s3.
parametercutoff
if provided, it's a cap on both the number of iterations, and on the result. (since 3.0). This is useful if you just want to check whether the edit distance is less or equal than 2 (use cutoff of 3).