Basic String Utilstype 'a iter = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
include module type of struct include Stdlib .StringLabels end
val make : int -> char -> string
val init : int -> f :(int -> char) -> string
val of_bytes : bytes -> string
val to_bytes : string -> bytes
val get : string -> int -> char
val concat : sep :string -> string list -> string
val cat : string -> string -> string
val starts_with : prefix :string -> string -> bool
val ends_with : suffix :string -> string -> bool
val contains_from : string -> int -> char -> bool
val rcontains_from : string -> int -> char -> bool
val contains : string -> char -> bool
val sub : string -> pos :int -> len :int -> string
val map : f :(char -> char) -> string -> string
val mapi : f :(int -> char -> char) -> string -> string
val fold_left : f :('a -> char -> 'a ) -> init :'a -> string -> 'a
val fold_right : f :(char -> 'a -> 'a ) -> string -> init :'a -> 'a
val trim : string -> string
val escaped : string -> string
val iteri : f :(int -> char -> unit) -> string -> unit
val index_from : string -> int -> char -> int
val index_from_opt : string -> int -> char -> int option
val rindex_from : string -> int -> char -> int
val rindex_from_opt : string -> int -> char -> int option
val index : string -> char -> int
val index_opt : string -> char -> int option
val rindex : string -> char -> int
val rindex_opt : string -> char -> int option
val to_seqi : t -> (int * char) Stdlib .Seq.t
val get_utf_8_uchar : t -> int -> Stdlib .Uchar.utf_decode
val is_valid_utf_8 : t -> bool
val get_utf_16be_uchar : t -> int -> Stdlib .Uchar.utf_decode
val is_valid_utf_16be : t -> bool
val get_utf_16le_uchar : t -> int -> Stdlib .Uchar.utf_decode
val is_valid_utf_16le : t -> bool
val create : int -> bytes
val copy : string -> string
val fill : bytes -> pos :int -> len :int -> char -> unit
val uppercase : string -> string
val lowercase : string -> string
val capitalize : string -> string
val uncapitalize : string -> string
val get_uint8 : string -> int -> int
val get_int8 : string -> int -> int
val get_uint16_ne : string -> int -> int
val get_uint16_be : string -> int -> int
val get_uint16_le : string -> int -> int
val get_int16_ne : string -> int -> int
val get_int16_be : string -> int -> int
val get_int16_le : string -> int -> int
val get_int32_ne : string -> int -> int32
val get_int32_be : string -> int -> int32
val get_int32_le : string -> int -> int32
val get_int64_ne : string -> int -> int64
val get_int64_be : string -> int -> int64
val get_int64_le : string -> int -> int64
val unsafe_get : string -> int -> char
val unsafe_set : bytes -> int -> char -> unit
val unsafe_blit :
src :string ->
src_pos :int ->
dst :bytes ->
dst_pos :int ->
len :int ->
unit
val unsafe_fill : bytes -> pos :int -> len :int -> char -> unit
Return the length (number of characters) of the given string.
val blit :
src :t ->
src_pos :int ->
dst :Stdlib .Bytes.t ->
dst_pos :int ->
len :int ->
unit
Like String.blit
. Compatible with the -safe-string
option.
val fold : f :('a -> char -> 'a ) -> init :'a -> t -> 'a
Fold on chars by increasing index.
Conversionsval to_gen : t -> char gen
Return the gen
of characters contained in the string.
val to_iter : t -> char iter
Return the iter
of characters contained in the string.
val to_seq : t -> char Stdlib .Seq.t
to_seq s
returns a Seq.t
of the bytes in s
. Renamed from to std_seq
since 3.0.
val to_list : t -> char list
Return the list of characters contained in the string.
val pp_buf : Stdlib .Buffer.t -> t -> unit
Renamed from pp
since 2.0.
val pp : Stdlib .Format.formatter -> t -> unit
Print the string within quotes.
Renamed from print
since 2.0.
Stringsval equal : string -> string -> bool
Equality function on strings.
val compare : string -> string -> int
val is_empty : string -> bool
is_empty s
returns true
iff s
is empty (i.e. its length is 0).
val rev : string -> string
rev s
returns the reverse of s
.
val pad : ?side :[ `Left | `Right ] -> ?c :char -> int -> string -> string
pad n str
ensures that str
is at least n
bytes long, and pads it on the side
with c
if it's not the case.
val of_char : char -> string
val of_gen : char gen -> string
Convert a gen
of characters to a string.
val of_iter : char iter -> string
Convert a iter
of characters to a string.
val of_seq : char Stdlib .Seq.t -> string
Convert a sequence
of characters to a string. Renamed from of_std_seq
since 3.0.
val of_list : char list -> string
Convert a list of characters to a string.
val of_array : char array -> string
Convert an array of characters to a string.
val to_array : string -> char array
Return the array of characters contained in the string.
val find : ?start :int -> sub :string -> string -> int
Find sub
in string, returns its first index or -1
.
val find_all : ?start :int -> sub :string -> string -> int gen
find_all ~sub s
finds all occurrences of sub
in s
, even overlapping instances.
val find_all_l : ?start :int -> sub :string -> string -> int list
find_all_l ~sub s
finds all occurrences of sub
in s
and returns them in a list.
val mem : ?start :int -> sub :string -> string -> bool
mem ~sub s
is true
iff sub
is a substring of s
.
val rfind : sub :string -> string -> int
Find sub
in string from the right, returns its first index or -1
. Should only be used with very small sub
.
val replace :
?which :[ `Left | `Right | `All ] ->
sub :string ->
by :string ->
string ->
string
replace ~sub ~by s
replaces some occurrences of sub
by by
in s
.
val is_sub :
sub :string ->
sub_pos :int ->
string ->
pos :int ->
sub_len :int ->
bool
is_sub ~sub i s j ~len
returns true
iff the substring of sub
starting at position i
and of length len
is a substring of s
starting at position j
.
val repeat : string -> int -> string
The same string, repeated n 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
.
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.
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.
val take : int -> string -> string
take n s
keeps only the n
first chars of s
.
val drop : int -> string -> string
drop n s
removes the n
first chars of s
.
val take_drop : int -> string -> string * string
take_drop n s = take n s, drop n s
.
val lines : string -> string list
lines s
returns a list of the lines of s
(splits along '\n').
val lines_gen : string -> string gen
lines_gen s
returns a generator of the lines of s
(splits along '\n').
val concat_gen : sep :string -> string gen -> string
concat_gen ~sep g
concatenates all strings of g
, separated with sep
.
val unlines : string list -> string
unlines l
concatenates all strings of l
, separated with '\n'.
val unlines_gen : string gen -> string
unlines_gen g
concatenates all strings of g
, separated with '\n'.
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
.
val iter : f :(char -> unit) -> string -> unit
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).
val filter : f :(char -> bool) -> string -> string
filter f s
discards characters not satisfying f
.
val flat_map : ?sep :string -> f :(char -> string) -> string -> string
Map each chars to a string, then concatenates them all.
val for_all : f :(char -> bool) -> string -> bool
val exists : f :(char -> bool) -> string -> bool
val drop_while : f :(char -> bool) -> t -> t
drop_while f s
discards any characters starting from the left, up to the first character c
not satisfying f c
.
val rdrop_while : f :(char -> bool) -> t -> t
rdrop_while f s
discards any characters starting from the right, up to the first character c
not satisfying f c
.
Trim space on the left (see String.trim
for more details).
Trim space on the right (see String.trim
for more details).
Operations on 2 stringsval map2 : f :(char -> char -> char) -> string -> string -> string
val iter2 : f :(char -> char -> unit) -> string -> string -> unit
Iterate on pairs of chars.
val iteri2 : f :(int -> char -> char -> unit) -> string -> string -> unit
Iterate on pairs of chars with their index.
val fold2 : f :('a -> char -> char -> 'a ) -> init :'a -> string -> string -> 'a
val for_all2 : f :(char -> char -> bool) -> string -> string -> bool
All pairs of chars respect the predicate?
val exists2 : f :(char -> char -> bool) -> string -> string -> bool
Ascii functionsThose functions are deprecated in String
since 4.03, so we provide a stable alias for them even in older versions.
val capitalize_ascii : string -> string
val uncapitalize_ascii : string -> string
val uppercase_ascii : string -> string
val lowercase_ascii : string -> string
val equal_caseless : string -> string -> bool
Comparison without respect to ascii lowercase.
FindingA relatively efficient algorithm for finding sub-strings.
module Find : sig ... end
Splittingmodule Split : sig ... end
val split_on_char : by :char -> string -> string list
Split the string along the given char.
val split : by :string -> string -> string list
Utilsval compare_versions : string -> string -> int
compare_versions a b
compares version strings a
and b
, considering that numbers are above text.
val compare_natural : string -> string -> int
Natural Sort Order, comparing chunks of digits as natural numbers. https://en.wikipedia.org/wiki/Natural_sort_order
val edit_distance : ?cutoff :int -> string -> string -> int
Edition distance between two strings. This satisfies the classical distance axioms: it is always positive, symmetric, and satisfies the formula distance a b + distance b c >= distance a c
.
Infix operatorsmodule Infix : sig ... end
include module type of Infix
val (<>) : t -> t -> bool
val (<=) : t -> t -> bool
val (>=) : t -> t -> bool