Module CCString
Basic String Utils
type 'a gen= unit -> 'a optiontype 'a sequence= ('a -> unit) -> unittype 'a klist= unit -> [ `Nil | `Cons of 'a * 'a klist ]
Common Signature
module type S = sig ... endStrings
include module type of sig ... end
val length : string -> intval get : string -> int -> charval set : bytes -> int -> char -> unitval create : int -> bytes
val make : int -> char -> stringval init : int -> (int -> char) -> stringval copy : string -> stringval sub : string -> int -> int -> stringval fill : bytes -> int -> int -> char -> unitval blit : string -> int -> bytes -> int -> int -> unitval concat : string -> string list -> stringval iter : (char -> unit) -> string -> unitval iteri : (int -> char -> unit) -> string -> unitval map : (char -> char) -> string -> stringval mapi : (int -> char -> char) -> string -> stringval trim : string -> stringval escaped : string -> stringval index : string -> char -> intval index_opt : string -> char -> int optionval rindex : string -> char -> intval rindex_opt : string -> char -> int optionval index_from : string -> int -> char -> intval index_from_opt : string -> int -> char -> int optionval rindex_from : string -> int -> char -> intval rindex_from_opt : string -> int -> char -> int optionval contains : string -> char -> boolval contains_from : string -> int -> char -> boolval rcontains_from : string -> int -> char -> boolval uppercase : string -> stringval lowercase : string -> stringval capitalize : string -> stringval uncapitalize : string -> stringval uppercase_ascii : string -> stringval lowercase_ascii : string -> stringval capitalize_ascii : string -> stringval uncapitalize_ascii : string -> string
val compare : string -> string -> intval is_empty : string -> boolis_empty sreturnstrueiffsis empty (i.e. its length is 0).- since
 - 1.5
 
val pad : ?side:[ `Left | `Right ] -> ?c:char -> int -> string -> stringpad n strensures thatstris at leastnbytes long, and pads it on thesidewithcif it's not the case.- parameter side
 determines where padding occurs (default:
`Left).
- parameter c
 the char used to pad (default: ' ').
- since
 - 0.17
 
val of_gen : char gen -> stringConvert a
genof characters to a string.
val of_seq : char sequence -> stringConvert a
sequenceof characters to a string.
val of_klist : char klist -> stringConvert a
klistof characters to a string.
val find : ?start:int -> sub:string -> string -> intFind
subin string, returns its first index or-1.
val find_all : ?start:int -> sub:string -> string -> int genfind_all ~sub sfinds all occurrences ofsubins, even overlapping instances.- parameter start
 starting position in
s.
- since
 - 0.17
 
val find_all_l : ?start:int -> sub:string -> string -> int listfind_all_l ~sub sfinds all occurrences ofsubinsand returns them in a list.- parameter start
 starting position in
s.
- since
 - 0.17
 
val mem : ?start:int -> sub:string -> string -> boolmem ~sub sistrueiffsubis a substring ofs.- since
 - 0.12
 
val rfind : sub:string -> string -> intFind
subin string from the right, returns its first index or-1. Should only be used with very smallsub.- since
 - 0.12
 
val replace : ?which:[ `Left | `Right | `All ] -> sub:string -> by:string -> string -> stringreplace ~sub ~by sreplaces some occurrences ofsubbybyins.- parameter which
 decides whether the occurrences to replace are:
`Leftfirst occurrence from the left (beginning).`Rightfirst occurrence from the right (end).`Allall occurrences (default).
- raises Invalid_argument
 if
sub = "".
- since
 - 0.14
 
val is_sub : sub:string -> int -> string -> int -> sub_len:int -> boolis_sub ~sub i s j ~lenreturnstrueiff the substring ofsubstarting at positioniand of lengthlenis a substring ofsstarting at positionj.
val suffix : suf:string -> string -> boolsuffix ~suf sreturnstrueiffsufis a suffix ofs.- since
 - 0.7
 
val chop_prefix : pre:string -> string -> string optionchop_prefix ~pre sremovesprefromsifprereally is a prefix ofs, returnsNoneotherwise.- since
 - 0.17
 
val chop_suffix : suf:string -> string -> string optionchop_suffix ~suf sremovessuffromsifsufreally is a suffix ofs, returnsNoneotherwise.- since
 - 0.17
 
val lines : string -> string listlines sreturns a list of the lines ofs(splits along '\n').- since
 - 0.10
 
val lines_gen : string -> string genlines_gen sreturns a generator of the lines ofs(splits along '\n').- since
 - 0.10
 
val concat_gen : sep:string -> string gen -> stringconcat_gen ~sep gconcatenates all strings ofg, separated withsep.- since
 - 0.10
 
val unlines : string list -> stringunlines lconcatenates all strings ofl, separated with '\n'.- since
 - 0.10
 
val unlines_gen : string gen -> stringunlines_gen gconcatenates all strings ofg, separated with '\n'.- since
 - 0.10
 
val set : string -> int -> char -> stringset s i ccreates a new string which is a copy ofs, except for indexi, which becomesc.- raises Invalid_argument
 if
iis an invalid index.
- since
 - 0.12
 
val filter_map : (char -> char option) -> string -> stringfilter_map f scalls(f a0) (f a1) ... (f an)wherea0 ... anare the characters of s. It returns the string of characterscisuch asf ai = Some ci(whenfreturnsNone, the corresponding element ofsis discarded).- since
 - 0.17
 
val filter : (char -> bool) -> string -> stringfilter f sdiscards characters not satisfyingf.- since
 - 0.17
 
val flat_map : ?sep:string -> (char -> string) -> string -> stringMap each chars to a string, then concatenates them all.
- parameter sep
 optional separator between each generated string.
- since
 - 0.12
 
include S with type S.t := string
val length : t -> intReturn the length (number of characters) of the given string.
val blit : t -> int -> Stdlib.Bytes.t -> int -> int -> unitLike
String.blit. Compatible with the-safe-stringoption.- raises Invalid_argument
 if indices are not valid.
val fold : ('a -> char -> 'a) -> 'a -> t -> 'aFold on chars by increasing index.
- since
 - 0.7
 
Conversions
val to_list : t -> char listReturn the list of characters contained in the string.
val pp_buf : Stdlib.Buffer.t -> t -> unitRenamed from
ppsince 2.0.
val pp : Stdlib.Format.formatter -> t -> unitPrint the string within quotes.
Renamed from
printsince 2.0.
val drop_while : (char -> bool) -> t -> tdrop_while f sdiscards any characters starting from the left, up to the first charactercnot satisfyingf c.- since
 - 2.2
 
Operations on 2 strings
val map2 : (char -> char -> char) -> string -> string -> stringMap pairs of chars.
- raises Invalid_argument
 if the strings have not the same length.
- since
 - 0.12
 
val iter2 : (char -> char -> unit) -> string -> string -> unitIterate on pairs of chars.
- raises Invalid_argument
 if the strings have not the same length.
- since
 - 0.12
 
val iteri2 : (int -> char -> char -> unit) -> string -> string -> unitIterate on pairs of chars with their index.
- raises Invalid_argument
 if the strings have not the same length.
- since
 - 0.12
 
val fold2 : ('a -> char -> char -> 'a) -> 'a -> string -> string -> 'aFold on pairs of chars.
- raises Invalid_argument
 if the strings have not the same length.
- since
 - 0.12
 
Ascii functions
Those functions are deprecated in String since 4.03, so we provide a stable alias for them even in older versions.
Finding
A relatively efficient algorithm for finding sub-strings.
- since
 - 1.0
 
module Find : sig ... endSplitting
module Split : sig ... endval split : by:string -> string -> string listAlias to
Split.list_cpy.- since
 - 1.2
 
Utils
val compare_versions : string -> string -> intcompare_versions a bcompares version stringsaandb, considering that numbers are above text.- since
 - 0.13
 
Slices
A contiguous part of a string
module Sub : sig ... end