.TH "String" 3o 2012-06-26 OCamldoc "OCaml library" .SH NAME String \- String operations. .SH Module Module String .SH Documentation .sp Module .BI "String" : .B sig end .sp String operations\&. Given a string .B s of length .B l , we call character number in .B s the index of a character in .B s \&. Indexes start at .B 0 , and we will call a character number valid in .B s if it falls within the range .B [0\&.\&.\&.l\-1] \&. A position is the point between two characters or at the beginning or end of the string\&. We call a position valid in .B s if it falls within the range .B [0\&.\&.\&.l] \&. Note that character number .B n is between positions .B n and .B n+1 \&. .sp Two parameters .B start and .B len are said to designate a valid substring of .B s if .B len >= 0 and .B start and .B start+len are valid positions in .B s \&. .sp .sp .sp .sp .I val length : .B string -> int .sp Return the length (number of characters) of the given string\&. .sp .sp .I val get : .B string -> int -> char .sp .B String\&.get s n returns character number .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 character number in .B s \&. .sp .sp .I val set : .B string -> int -> char -> unit .sp .B String\&.set s n c modifies string .B s in place, replacing the character number .B n by .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 character number in .B s \&. .sp .sp .I val create : .B int -> string .sp .B String\&.create n returns a fresh string of length .B n \&. The string initially contains arbitrary characters\&. .sp Raise .B Invalid_argument if .B n < 0 or .B n > .B Sys\&.max_string_length \&. .sp .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 .sp .I val copy : .B string -> string .sp Return a copy of the given string\&. .sp .sp .I val sub : .B string -> int -> 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 .sp .I val fill : .B string -> int -> int -> char -> unit .sp .B String\&.fill s start len c modifies string .B s in place, replacing .B len characters 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 .sp .I val blit : .B string -> int -> string -> int -> int -> unit .sp .B String\&.blit src srcoff dst dstoff len copies .B len characters from string .B src , starting at character number .B srcoff , to string .B dst , starting at character number .B dstoff \&. It works correctly even if .B src and .B dst are the same string, and the source and destination intervals overlap\&. .sp Raise .B Invalid_argument if .B srcoff and .B len do not designate a valid substring of .B src , or if .B dstoff and .B len do not designate a valid substring of .B dst \&. .sp .sp .I val concat : .B 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 .sp .I val iter : .B (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 .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 Objective Caml\&. If there is no special character in the argument, return the original string itself, not a copy\&. .sp .sp .I val index : .B string -> char -> int .sp .B String\&.index s c returns the character number 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 .sp .I val rindex : .B string -> char -> int .sp .B String\&.rindex s c returns the character number 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 .sp .I val index_from : .B string -> int -> char -> int .sp .B String\&.index_from s i c returns the character number 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 .sp .I val rindex_from : .B string -> int -> char -> int .sp .B String\&.rindex_from s i c returns the character number 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 .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 .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 .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 .sp .I val uppercase : .B string -> string .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 .sp .I val lowercase : .B string -> string .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 .sp .I val capitalize : .B string -> string .sp Return a copy of the argument, with the first character set to uppercase\&. .sp .sp .I val uncapitalize : .B string -> string .sp Return a copy of the argument, with the first character set to lowercase\&. .sp .sp .I type t = .B string .sp An alias for the type of strings\&. .sp .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 .sp