An indexi of s is an integer in the range [0;n-1]. It represents the ith byte (character) of s which can be accessed using the constant time string indexing operator s.[i].
A positioni of s is an integer in the range [0;n]. It represents either the point at the beginning of the string, or the point between two indices, or the point at the end of the string. The ith byte index is between position i and i+1.
Two integers start and len are said to define a valid substring of s if len >= 0 and start, start+len are positions of s.
Unicode text. Strings being arbitrary sequences of bytes, they can hold any kind of textual encoding. However the recommended encoding for storing Unicode text in OCaml strings is UTF-8. This is the encoding used by Unicode escapes in string literals. For example the string "\u{1F42B}" is the UTF-8 encoding of the Unicode character U+1F42B.
Past mutability. OCaml strings used to be modifiable in place, for instance via the String.set and String.blit functions. This use is nowadays only possible when the compiler is put in "unsafe-string" mode by giving the -unsafe-string command-line option. This compatibility mode makes the types string and bytes (see Bytes.t) interchangeable so that functions expecting byte sequences can also accept strings as arguments and modify them.
The distinction between bytes and string was introduced in OCaml 4.02, and the "unsafe-string" compatibility mode was the default until OCaml 4.05. Starting with 4.06, the compatibility mode is opt-in; we intend to remove the option in the future.
The labeled version of this module can be used as described in the StdLabels module.
Strings
type t = string
The type for strings.
val make : int ->char -> string
make n c is a string of length n with each index holding the character c.
to_seq s is a sequence made of the string's characters in increasing order. In "unsafe-string" mode, modifications of the string during iteration will be reflected in the iterator.
val blit : string ->int ->bytes ->int ->int -> unit
blit src src_pos dst dst_pos len copies len bytes from the string src, starting at index src_pos, to byte sequence dst, starting at character number dst_pos.
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.