Module Caml.String
val get : string -> int -> charString.get s nreturns the character at indexnin strings. You can also writes.[n]instead ofString.get s n.Raise
Invalid_argumentifnnot a valid index ins.
val set : bytes -> int -> char -> unitString.set s n cmodifies byte sequencesin place, replacing the byte at indexnwithc. You can also writes.[n] <- cinstead ofString.set s n c.Raise
Invalid_argumentifnis not a valid index ins.- deprecated
This is a deprecated alias of
Bytes.set.
val create : int -> bytesString.create nreturns a fresh byte sequence of lengthn. The sequence is uninitialized and contains arbitrary bytes.Raise
Invalid_argumentifn < 0orn >Sys.max_string_length.- deprecated
This is a deprecated alias of
Bytes.create.
val make : int -> char -> stringString.make n creturns a fresh string of lengthn, filled with the characterc.Raise
Invalid_argumentifn < 0orn >Sys.max_string_length.
val init : int -> (int -> char) -> stringString.init n freturns a string of lengthn, with characteriinitialized to the result off i(called in increasing index order).Raise
Invalid_argumentifn < 0orn >Sys.max_string_length.- since
- 4.02.0
val copy : string -> stringReturn a copy of the given string.
- deprecated
Because strings are immutable, it doesn't make much sense to make identical copies of them.
val sub : string -> int -> int -> stringString.sub s start lenreturns a fresh string of lengthlen, containing the substring ofsthat starts at positionstartand has lengthlen.Raise
Invalid_argumentifstartandlendo not designate a valid substring ofs.
val fill : bytes -> int -> int -> char -> unitString.fill s start len cmodifies byte sequencesin place, replacinglenbytes withc, starting atstart.Raise
Invalid_argumentifstartandlendo not designate a valid range ofs.- deprecated
This is a deprecated alias of
Bytes.fill.
val blit : string -> int -> bytes -> int -> int -> unitSame as
Bytes.blit_string.
val concat : string -> string list -> stringString.concat sep slconcatenates the list of stringssl, inserting the separator stringsepbetween each.Raise
Invalid_argumentif the result is longer thanSys.max_string_lengthbytes.
val iter : (char -> unit) -> string -> unitString.iter f sapplies functionfin turn to all the characters ofs. It is equivalent tof s.[0]; f s.[1]; ...; f s.[String.length s - 1]; ().
val iteri : (int -> char -> unit) -> string -> unitSame as
String.iter, but the function is applied to the index of the element as first argument (counting from 0), and the character itself as second argument.- since
- 4.00.0
val map : (char -> char) -> string -> stringString.map f sapplies functionfin turn to all the characters ofs(in increasing index order) and stores the results in a new string that is returned.- since
- 4.00.0
val mapi : (int -> char -> char) -> string -> stringString.mapi f scallsfwith each character ofsand its index (in increasing index order) and stores the results in a new string that is returned.- since
- 4.02.0
val trim : string -> stringReturn a copy of the argument, without leading and trailing whitespace. The characters regarded as whitespace are:
' ','\012','\n','\r', and'\t'. If there is neither leading nor trailing whitespace character in the argument, return the original string itself, not a copy.- since
- 4.00.0
val escaped : string -> stringReturn a copy of the argument, with special characters represented by escape sequences, following the lexical conventions of OCaml. All characters outside the ASCII printable range (32..126) are escaped, as well as backslash and double-quote.
If there is no special character in the argument that needs escaping, return the original string itself, not a copy.
Raise
Invalid_argumentif the result is longer thanSys.max_string_lengthbytes.The function
Scanf.unescapedis a left inverse ofescaped, i.e.Scanf.unescaped (escaped s) = sfor any strings(unlessescape sfails).
val index : string -> char -> intString.index s creturns the index of the first occurrence of charactercin strings.Raise
Not_foundifcdoes not occur ins.
val index_opt : string -> char -> int optionString.index_opt s creturns the index of the first occurrence of charactercin strings, orNoneifcdoes not occur ins.- since
- 4.05
val rindex : string -> char -> intString.rindex s creturns the index of the last occurrence of charactercin strings.Raise
Not_foundifcdoes not occur ins.
val rindex_opt : string -> char -> int optionString.rindex_opt s creturns the index of the last occurrence of charactercin strings, orNoneifcdoes not occur ins.- since
- 4.05
val index_from : string -> int -> char -> intString.index_from s i creturns the index of the first occurrence of charactercin stringsafter positioni.String.index s cis equivalent toString.index_from s 0 c.Raise
Invalid_argumentifiis not a valid position ins. RaiseNot_foundifcdoes not occur insafter positioni.
val index_from_opt : string -> int -> char -> int optionString.index_from_opt s i creturns the index of the first occurrence of charactercin stringsafter positioniorNoneifcdoes not occur insafter positioni.String.index_opt s cis equivalent toString.index_from_opt s 0 c. RaiseInvalid_argumentifiis not a valid position ins.- since
- 4.05
val rindex_from : string -> int -> char -> intString.rindex_from s i creturns the index of the last occurrence of charactercin stringsbefore positioni+1.String.rindex s cis equivalent toString.rindex_from s (String.length s - 1) c.Raise
Invalid_argumentifi+1is not a valid position ins. RaiseNot_foundifcdoes not occur insbefore positioni+1.
val rindex_from_opt : string -> int -> char -> int optionString.rindex_from_opt s i creturns the index of the last occurrence of charactercin stringsbefore positioni+1orNoneifcdoes not occur insbefore positioni+1.String.rindex_opt s cis equivalent toString.rindex_from_opt s (String.length s - 1) c.Raise
Invalid_argumentifi+1is not a valid position ins.- since
- 4.05
val contains : string -> char -> boolString.contains s ctests if charactercappears in the strings.
val contains_from : string -> int -> char -> boolString.contains_from s start ctests if charactercappears insafter positionstart.String.contains s cis equivalent toString.contains_from s 0 c.Raise
Invalid_argumentifstartis not a valid position ins.
val rcontains_from : string -> int -> char -> boolString.rcontains_from s stop ctests if charactercappears insbefore positionstop+1.Raise
Invalid_argumentifstop < 0orstop+1is not a valid position ins.
val uppercase : string -> stringReturn a copy of the argument, with all lowercase letters translated to uppercase, including accented letters of the ISO Latin-1 (8859-1) character set.
- deprecated
Functions operating on Latin-1 character set are deprecated.
val lowercase : string -> stringReturn a copy of the argument, with all uppercase letters translated to lowercase, including accented letters of the ISO Latin-1 (8859-1) character set.
- deprecated
Functions operating on Latin-1 character set are deprecated.
val capitalize : string -> stringReturn a copy of the argument, with the first character set to uppercase, using the ISO Latin-1 (8859-1) character set..
- deprecated
Functions operating on Latin-1 character set are deprecated.
val uncapitalize : string -> stringReturn a copy of the argument, with the first character set to lowercase, using the ISO Latin-1 (8859-1) character set..
- deprecated
Functions operating on Latin-1 character set are deprecated.
val uppercase_ascii : string -> stringReturn a copy of the argument, with all lowercase letters translated to uppercase, using the US-ASCII character set.
- since
- 4.03.0
val lowercase_ascii : string -> stringReturn a copy of the argument, with all uppercase letters translated to lowercase, using the US-ASCII character set.
- since
- 4.03.0
val capitalize_ascii : string -> stringReturn a copy of the argument, with the first character set to uppercase, using the US-ASCII character set.
- since
- 4.03.0
val uncapitalize_ascii : string -> stringReturn a copy of the argument, with the first character set to lowercase, using the US-ASCII character set.
- since
- 4.03.0
val compare : t -> t -> intThe comparison function for strings, with the same specification as
Stdlib.compare. Along with the typet, this functioncompareallows the moduleStringto be passed as argument to the functorsSet.MakeandMap.Make.
val split_on_char : char -> string -> string listString.split_on_char sep sreturns the list of all (possibly empty) substrings ofsthat are delimited by thesepcharacter.The function's output is specified by the following invariants:
- The list is not empty.
- Concatenating its elements using
sepas a separator returns a string equal to the input (String.concat (String.make 1 sep) (String.split_on_char sep s) = s). - No string in the result contains the
sepcharacter.
- since
- 4.04.0
Iterators
val to_seq : t -> char Seq.tIterate on the string, in increasing index order. Modifications of the string during iteration will be reflected in the iterator.
- since
- 4.07