Return 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 -> string
Return 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.
The function Scanf.unescaped is a left inverse of escaped, i.e. Scanf.unescaped (escaped s) = s for any string s (unless escape s fails).
val index : string ->char -> int
String.index s c returns the index of the first occurrence of character c in string s.
Raise Not_found if c does not occur in s.
val index_opt : string ->char ->int option
String.index_opt s c returns the index of the first occurrence of character c in string s, or None if c does not occur in s.
since 4.05
val rindex : string ->char -> int
String.rindex s c returns the index of the last occurrence of character c in string s.
Raise Not_found if c does not occur in s.
val rindex_opt : string ->char ->int option
String.rindex_opt s c returns the index of the last occurrence of character c in string s, or None if c does not occur in s.
since 4.05
val index_from : string ->int ->char -> int
String.index_from s i c returns the index of the first occurrence of character c in string s after position i. String.index s c is equivalent to String.index_from s 0 c.
Raise Invalid_argument if i is not a valid position in s. Raise Not_found if c does not occur in s after position i.
val index_from_opt : string ->int ->char ->int option
String.index_from_opt s i c returns the index of the first occurrence of character c in string s after position i or None if c does not occur in s after position i.
String.index_opt s c is equivalent to String.index_from_opt s 0 c. Raise Invalid_argument if i is not a valid position in s.
since 4.05
val rindex_from : string ->int ->char -> int
String.rindex_from s i c returns the index of the last occurrence of character c in string s before position i+1. String.rindex s c is equivalent to String.rindex_from s (String.length s - 1) c.
Raise Invalid_argument if i+1 is not a valid position in s. Raise Not_found if c does not occur in s before position i+1.
val rindex_from_opt : string ->int ->char ->int option
String.rindex_from_opt s i c returns the index of the last occurrence of character c in string s before position i+1 or None if c does not occur in s before position i+1.
String.rindex_opt s c is equivalent to String.rindex_from_opt s (String.length s - 1) c.
Raise Invalid_argument if i+1 is not a valid position in s.
since 4.05
val contains : string ->char -> bool
String.contains s c tests if character c appears in the string s.
val contains_from : string ->int ->char -> bool
String.contains_from s start c tests if character c appears in s after position start. String.contains s c is equivalent to String.contains_from s 0 c.
Raise Invalid_argument if start is not a valid position in s.
val rcontains_from : string ->int ->char -> bool
String.rcontains_from s stop c tests if character c appears in s before position stop+1.
Raise Invalid_argument if stop < 0 or stop+1 is not a valid position in s.
val uppercase : string -> string
Return 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 -> string
Return 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 -> string
Return 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 -> string
Return 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.
replace ~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 ->int ->string ->int ->sub_len:int -> bool
is_sub ~sub i s j ~sub_len returns true iff the substring of sub starting at position i and of length sub_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.
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 = 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').
val filter_map : (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 : (char -> bool)->string -> string
filter f s discards characters not satisfying f.
since 0.17
val flat_map : ?sep:string ->(char -> string)->string -> string
Map each chars to a string, then concatenates them all.
compare_versions a b compares version strings a and b, considering that numbers are above text.
since 0.13
val compare_natural : string ->string -> int
Natural Sort Order, comparing chunks of digits as natural numbers. https://en.wikipedia.org/wiki/Natural_sort_order
since 1.3
val edit_distance : 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.