.TH "StdLabels.String" 3o source: 2019-01-25 OCamldoc "OCaml library" .SH NAME StdLabels.String \- no description .SH Module Module StdLabels.String .SH Documentation .sp Module .BI "String" : .B (module StringLabels) .sp .sp .sp .sp .I val length : .B string -> int .sp Return the length (number of characters) of the given string\&. .sp .I val get : .B string -> int -> char .sp .B String\&.get s n returns the character at index .B n in string .B s \&. You can also write .B s\&.[n] instead of .B String\&.get s n \&. .sp Raise .B Invalid_argument if .B n not a valid index in .B s \&. .sp .I val set : .B bytes -> int -> char -> unit .sp .B "Deprecated." This is a deprecated alias of .B BytesLabels\&.set \&. .sp .B String\&.set s n c modifies byte sequence .B s in place, replacing the byte at index .B n with .B c \&. You can also write .B s\&.[n] <\- c instead of .B String\&.set s n c \&. .sp Raise .B Invalid_argument if .B n is not a valid index in .B s \&. .sp .I val create : .B int -> bytes .sp .B "Deprecated." This is a deprecated alias of .B BytesLabels\&.create \&. .sp .B String\&.create n returns a fresh byte sequence of length .B n \&. The sequence is uninitialized and contains arbitrary bytes\&. .sp Raise .B Invalid_argument if .B n < 0 or .B n > .B Sys\&.max_string_length \&. .sp .I val make : .B int -> char -> string .sp .B String\&.make n c returns a fresh string of length .B n , filled with the character .B c \&. .sp Raise .B Invalid_argument if .B n < 0 or .B n > .B Sys\&.max_string_length \&. .sp .I val init : .B int -> f:(int -> char) -> string .sp .B init n f returns a string of length .B n , with character .B i initialized to the result of .B f i \&. .sp Raise .B Invalid_argument if .B n < 0 or .B n > .B Sys\&.max_string_length \&. .sp .B "Since" 4.02.0 .sp .I val copy : .B string -> string .sp Return a copy of the given string\&. .sp .I val sub : .B string -> pos:int -> len:int -> string .sp .B String\&.sub s start len returns a fresh string of length .B len , containing the substring of .B s that starts at position .B start and has length .B len \&. .sp Raise .B Invalid_argument if .B start and .B len do not designate a valid substring of .B s \&. .sp .I val fill : .B bytes -> pos:int -> len:int -> char -> unit .sp .B "Deprecated." This is a deprecated alias of .B BytesLabels\&.fill \&. .sp .B String\&.fill s start len c modifies byte sequence .B s in place, replacing .B len bytes by .B c , starting at .B start \&. .sp Raise .B Invalid_argument if .B start and .B len do not designate a valid substring of .B s \&. .sp .I val blit : .B src:string -> src_pos:int -> dst:bytes -> dst_pos:int -> len:int -> unit .sp .B String\&.blit src srcoff dst dstoff len copies .B len bytes from the string .B src , starting at index .B srcoff , to byte sequence .B dst , starting at character number .B dstoff \&. .sp Raise .B Invalid_argument if .B srcoff and .B len do not designate a valid range of .B src , or if .B dstoff and .B len do not designate a valid range of .B dst \&. .sp .I val concat : .B sep:string -> string list -> string .sp .B String\&.concat sep sl concatenates the list of strings .B sl , inserting the separator string .B sep between each\&. .sp .I val iter : .B f:(char -> unit) -> string -> unit .sp .B String\&.iter f s applies function .B f in turn to all the characters of .B s \&. It is equivalent to .B f s\&.[0]; f s\&.[1]; \&.\&.\&.; f s\&.[String\&.length s \- 1]; () \&. .sp .I val iteri : .B f:(int -> char -> unit) -> string -> unit .sp Same as .B 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\&. .sp .B "Since" 4.00.0 .sp .I val map : .B f:(char -> char) -> string -> string .sp .B String\&.map f s applies function .B f in turn to all the characters of .B s and stores the results in a new string that is returned\&. .sp .B "Since" 4.00.0 .sp .I val mapi : .B f:(int -> char -> char) -> string -> string .sp .B String\&.mapi f s calls .B f with each character of .B s and its index (in increasing index order) and stores the results in a new string that is returned\&. .sp .B "Since" 4.02.0 .sp .I val trim : .B string -> string .sp Return a copy of the argument, without leading and trailing whitespace\&. The characters regarded as whitespace are: .B \&' \&' , .B \&'\(rs012\&' , .B \&'\(rsn\&' , .B \&'\(rsr\&' , and .B \&'\(rst\&' \&. If there is no leading nor trailing whitespace character in the argument, return the original string itself, not a copy\&. .sp .B "Since" 4.00.0 .sp .I val escaped : .B string -> string .sp Return a copy of the argument, with special characters represented by escape sequences, following the lexical conventions of OCaml\&. If there is no special character in the argument, return the original string itself, not a copy\&. Its inverse function is Scanf\&.unescaped\&. .sp .I val index : .B string -> char -> int .sp .B String\&.index s c returns the index of the first occurrence of character .B c in string .B s \&. .sp Raise .B Not_found if .B c does not occur in .B s \&. .sp .I val index_opt : .B string -> char -> int option .sp .B String\&.index_opt s c returns the index of the first occurrence of character .B c in string .B s , or .B None if .B c does not occur in .B s \&. .sp .B "Since" 4.05 .sp .I val rindex : .B string -> char -> int .sp .B String\&.rindex s c returns the index of the last occurrence of character .B c in string .B s \&. .sp Raise .B Not_found if .B c does not occur in .B s \&. .sp .I val rindex_opt : .B string -> char -> int option .sp .B String\&.rindex_opt s c returns the index of the last occurrence of character .B c in string .B s , or .B None if .B c does not occur in .B s \&. .sp .B "Since" 4.05 .sp .I val index_from : .B string -> int -> char -> int .sp .B String\&.index_from s i c returns the index of the first occurrence of character .B c in string .B s after position .B i \&. .B String\&.index s c is equivalent to .B String\&.index_from s 0 c \&. .sp Raise .B Invalid_argument if .B i is not a valid position in .B s \&. Raise .B Not_found if .B c does not occur in .B s after position .B i \&. .sp .I val index_from_opt : .B string -> int -> char -> int option .sp .B String\&.index_from_opt s i c returns the index of the first occurrence of character .B c in string .B s after position .B i or .B None if .B c does not occur in .B s after position .B i \&. .sp .B String\&.index_opt s c is equivalent to .B String\&.index_from_opt s 0 c \&. Raise .B Invalid_argument if .B i is not a valid position in .B s \&. .sp .B "Since" 4.05 .sp .I val rindex_from : .B string -> int -> char -> int .sp .B String\&.rindex_from s i c returns the index of the last occurrence of character .B c in string .B s before position .B i+1 \&. .B String\&.rindex s c is equivalent to .B String\&.rindex_from s (String\&.length s \- 1) c \&. .sp Raise .B Invalid_argument if .B i+1 is not a valid position in .B s \&. Raise .B Not_found if .B c does not occur in .B s before position .B i+1 \&. .sp .I val rindex_from_opt : .B string -> int -> char -> int option .sp .B String\&.rindex_from_opt s i c returns the index of the last occurrence of character .B c in string .B s before position .B i+1 or .B None if .B c does not occur in .B s before position .B i+1 \&. .sp .B String\&.rindex_opt s c is equivalent to .B String\&.rindex_from_opt s (String\&.length s \- 1) c \&. .sp Raise .B Invalid_argument if .B i+1 is not a valid position in .B s \&. .sp .B "Since" 4.05 .sp .I val contains : .B string -> char -> bool .sp .B String\&.contains s c tests if character .B c appears in the string .B s \&. .sp .I val contains_from : .B string -> int -> char -> bool .sp .B String\&.contains_from s start c tests if character .B c appears in .B s after position .B start \&. .B String\&.contains s c is equivalent to .B String\&.contains_from s 0 c \&. .sp Raise .B Invalid_argument if .B start is not a valid position in .B s \&. .sp .I val rcontains_from : .B string -> int -> char -> bool .sp .B String\&.rcontains_from s stop c tests if character .B c appears in .B s before position .B stop+1 \&. .sp Raise .B Invalid_argument if .B stop < 0 or .B stop+1 is not a valid position in .B s \&. .sp .I val uppercase : .B string -> string .sp .B "Deprecated." Functions operating on Latin\-1 character set are deprecated\&. .sp 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\&. .sp .I val lowercase : .B string -> string .sp .B "Deprecated." Functions operating on Latin\-1 character set are deprecated\&. .sp 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\&. .sp .I val capitalize : .B string -> string .sp .B "Deprecated." Functions operating on Latin\-1 character set are deprecated\&. .sp Return a copy of the argument, with the first character set to uppercase, using the ISO Latin\-1 (8859\-1) character set\&.\&. .sp .I val uncapitalize : .B string -> string .sp .B "Deprecated." Functions operating on Latin\-1 character set are deprecated\&. .sp Return a copy of the argument, with the first character set to lowercase, using the ISO Latin\-1 (8859\-1) character set\&.\&. .sp .I val uppercase_ascii : .B string -> string .sp Return a copy of the argument, with all lowercase letters translated to uppercase, using the US\-ASCII character set\&. .sp .B "Since" 4.05.0 .sp .I val lowercase_ascii : .B string -> string .sp Return a copy of the argument, with all uppercase letters translated to lowercase, using the US\-ASCII character set\&. .sp .B "Since" 4.05.0 .sp .I val capitalize_ascii : .B string -> string .sp Return a copy of the argument, with the first character set to uppercase, using the US\-ASCII character set\&. .sp .B "Since" 4.05.0 .sp .I val uncapitalize_ascii : .B string -> string .sp Return a copy of the argument, with the first character set to lowercase, using the US\-ASCII character set\&. .sp .B "Since" 4.05.0 .sp .I type t = .B string .sp An alias for the type of strings\&. .sp .I val compare : .B t -> t -> int .sp The comparison function for strings, with the same specification as .B Pervasives\&.compare \&. Along with the type .B t , this function .B compare allows the module .B String to be passed as argument to the functors .B Set\&.Make and .B Map\&.Make \&. .sp .I val equal : .B t -> t -> bool .sp The equal function for strings\&. .sp .B "Since" 4.05.0 .sp .I val split_on_char : .B sep:char -> string -> string list .sp .B String\&.split_on_char sep s returns the list of all (possibly empty) substrings of .B s that are delimited by the .B sep character\&. .sp The function\&'s output is specified by the following invariants: .sp .sp \-The list is not empty\&. .sp \-Concatenating its elements using .B sep as a separator returns a string equal to the input ( .B String\&.concat (String\&.make 1 sep) .B (String\&.split_on_char sep s) = s )\&. .sp \-No string in the result contains the .B sep character\&. .sp .B "Since" 4.05.0 .sp