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.
Binary decoding of integers
The functions in this section binary decode integers from strings.
All following functions raise Invalid_argument if the characters needed at index i to decode the integer are not available.
Little-endian (resp. big-endian) encoding means that least (resp. most) significant bytes are stored first. Big-endian is also known as network byte order. Native-endian encoding is either little-endian or big-endian depending on Sys.big_endian.
32-bit and 64-bit integers are represented by the int32 and int64 types, which can be interpreted either as signed or unsigned numbers.
8-bit and 16-bit integers are represented by the int type, which has more bits than the binary encoding. These extra bits are sign-extended (or zero-extended) for functions which decode 8-bit or 16-bit integers and represented them with int values.
val get_uint8 : string ->int -> int
get_uint8 b i is b's unsigned 8-bit integer starting at character index i.
since 4.13.0
val get_int8 : string ->int -> int
get_int8 b i is b's signed 8-bit integer starting at character index i.
since 4.13.0
val get_uint16_ne : string ->int -> int
get_uint16_ne b i is b's native-endian unsigned 16-bit integer starting at character index i.
since 4.13.0
val get_uint16_be : string ->int -> int
get_uint16_be b i is b's big-endian unsigned 16-bit integer starting at character index i.
since 4.13.0
val get_uint16_le : string ->int -> int
get_uint16_le b i is b's little-endian unsigned 16-bit integer starting at character index i.
since 4.13.0
val get_int16_ne : string ->int -> int
get_int16_ne b i is b's native-endian signed 16-bit integer starting at character index i.
since 4.13.0
val get_int16_be : string ->int -> int
get_int16_be b i is b's big-endian signed 16-bit integer starting at character index i.
since 4.13.0
val get_int16_le : string ->int -> int
get_int16_le b i is b's little-endian signed 16-bit integer starting at character index i.
since 4.13.0
val get_int32_ne : string ->int -> int32
get_int32_ne b i is b's native-endian 32-bit integer starting at character index i.
since 4.13.0
val get_int32_be : string ->int -> int32
get_int32_be b i is b's big-endian 32-bit integer starting at character index i.
since 4.13.0
val get_int32_le : string ->int -> int32
get_int32_le b i is b's little-endian 32-bit integer starting at character index i.
since 4.13.0
val get_int64_ne : string ->int -> int64
get_int64_ne b i is b's native-endian 64-bit integer starting at character index i.
since 4.13.0
val get_int64_be : string ->int -> int64
get_int64_be b i is b's big-endian 64-bit integer starting at character index i.
since 4.13.0
val get_int64_le : string ->int -> int64
get_int64_le b i is b's little-endian 64-bit integer starting at character index i.
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.
val is_sub : sub:string ->int ->string ->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').
iter f s applies function f on each character of s. Alias to String.iter.
since 0.12
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 of s not satisfying f.
since 0.17
val uniq : (char ->char -> bool)->string -> string
uniq eq s remove consecutive duplicate characters in s.
since 3.4
val flat_map : ?sep:string ->(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 : (char -> bool)->string -> bool
for_all f s is true iff all characters of s satisfy the predicate f.
since 0.12
val exists : (char -> bool)->string -> bool
exists f s is true iff some character of s satisfy the predicate f.
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 the number of iterations. (since 3.0). This is useful if you just want to check whether the edit distance is less or equal than 2 without (use edit_distance s1 s2 ~cutoff:3 <= 2). note that contrary to what was previously documented here, the result can still be higher than cutoff if it's reached in <cutoff iterations. However if the result is < cutoff then it is accurate.