package extlib

  1. Overview
  2. Docs

Module ExtString.StringSource

Sourceval empty : string

The empty string.

New Functions
Sourceval init : int -> (int -> char) -> string

init l f returns the string of length l with the chars f 0 , f 1 , f 2 ... f (l-1).

Sourceval find : string -> string -> int

find s x returns the starting index of the string x within the string s or raises Invalid_string if x is not a substring of s.

Sourceval find_from : string -> int -> string -> int

find s i x returns the starting index of the string x within the string s (starting search from position i) or raises Invalid_string if no such substring exists. find s x is equivalent to find_from s 0 x.

Sourceval split : string -> string -> string * string

split s sep splits the string s between the first occurrence of sep. raises Invalid_string if the separator is not found.

Sourceval nsplit : string -> string -> string list

nsplit s sep splits the string s into a list of strings which are separated by sep. nsplit "" _ returns the empty list.

Sourceval join : string -> string list -> string

Same as concat

Sourceval slice : ?first:int -> ?last:int -> string -> string

slice ?first ?last s returns a "slice" of the string which corresponds to the characters s.[first], s.[first+1], ..., s[last-1]. Note that the character at index last is not included! If first is omitted it defaults to the start of the string, i.e. index 0, and if last is omitted is defaults to point just past the end of s, i.e. length s. Thus, slice s is equivalent to copy s.

Negative indexes are interpreted as counting from the end of the string. For example, slice ~last:-2 s will return the string s, but without the last two characters.

This function never raises any exceptions. If the indexes are out of bounds they are automatically clipped.

Sourceval lchop : string -> string

Returns the same string but without the first character. does nothing if the string is empty.

Sourceval rchop : string -> string

Returns the same string but without the last character. does nothing if the string is empty.

Sourceval of_int : int -> string

Returns the string representation of an int.

Sourceval of_float : float -> string

Returns the string representation of an float.

Sourceval of_char : char -> string

Returns a string containing one given character.

Sourceval to_int : string -> int

Returns the integer represented by the given string or raises Invalid_string if the string does not represent an integer.

Sourceval to_float : string -> float

Returns the float represented by the given string or raises Invalid_string if the string does not represent a float.

Sourceval ends_with : string -> suffix:string -> bool

ends_with s ~suffix returns true if the string s is ending with suffix.

Sourceval starts_with : string -> prefix:string -> bool

starts_with s ~prefix return true if s is starting with prefix.

Sourceval enum : string -> char Enum.t

Returns an enumeration of the characters of a string.

Sourceval of_enum : char Enum.t -> string

Creates a string from a character enumeration.

Sourceval map : (char -> char) -> string -> string

map f s returns a string where all characters c in s have been replaced by f c. *

Sourceval mapi : (int -> char -> char) -> string -> string

map f s returns a string where all characters c in s have been replaced by f i s.[i]. *

Sourceval iteri : (int -> char -> unit) -> string -> unit

Call f i s.[i] for every position i in string

Sourceval fold_left : ('a -> char -> 'a) -> 'a -> string -> 'a

fold_left f a s is f (... (f (f a s.[0]) s.[1]) ...) s.[n-1]

Sourceval fold_right : (char -> 'a -> 'a) -> string -> 'a -> 'a

fold_right f s b is f s.[0] (f s.[1] (... (f s.[n-1] b) ...))

Sourceval explode : string -> char list

explode s returns the list of characters in the string s.

Sourceval implode : char list -> string

implode cs returns a string resulting from concatenating the characters in the list cs.

Sourceval strip : ?chars:string -> string -> string

Returns the string without the chars if they are at the beginning or at the end of the string. By default chars are " \t\r\n".

Sourceval exists : string -> sub:string -> bool

exists str ~sub returns true if sub is a substring of str or false otherwise.

Sourceval replace_chars : (char -> string) -> string -> string

replace_chars f s returns a string where all chars c of s have been replaced by the string returned by f c.

Sourceval replace : str:string -> sub:string -> by:string -> bool * string

replace ~str ~sub ~by returns a tuple constisting of a boolean and a string where the first occurrence of the string sub within str has been replaced by the string by. The boolean is true if a subtitution has taken place.

Sourceval trim : string -> string

Return a copy of the argument, without leading and trailing whitespace. The characters regarded as whitespace are: ' ', '\012', '\n', '\r', and '\t'. (Note that it is different from strip defaults).

Compatibility Functions
Sourceval uppercase_ascii : string -> string
Sourceval lowercase_ascii : string -> string
Sourceval capitalize_ascii : string -> string
Sourceval uncapitalize_ascii : string -> string
Sourceval split_on_char : char -> string -> string list
Older Functions

Please refer to the OCaml Manual for documentation of these functions.

Sourceval length : string -> int
Sourceval get : string -> int -> char
Sourceval set : Bytes.t -> int -> char -> unit
  • deprecated Use Bytes.set instead.
Sourceval create : int -> Bytes.t
  • deprecated Use Bytes.create instead.
Sourceval make : int -> char -> string
Sourceval copy : string -> string
  • deprecated
Sourceval sub : string -> int -> int -> string
Sourceval fill : Bytes.t -> int -> int -> char -> unit
  • deprecated Use Bytes.fill instead.
Sourceval blit : string -> int -> Bytes.t -> int -> int -> unit
Sourceval concat : string -> string list -> string
Sourceval iter : (char -> unit) -> string -> unit
Sourceval escaped : string -> string
Sourceval index : string -> char -> int
Sourceval index_opt : string -> char -> int option
Sourceval rindex : string -> char -> int
Sourceval rindex_opt : string -> char -> int option
Sourceval index_from : string -> int -> char -> int
Sourceval index_from_opt : string -> int -> char -> int option
Sourceval rindex_from : string -> int -> char -> int
Sourceval rindex_from_opt : string -> int -> char -> int option
Sourceval contains : string -> char -> bool
Sourceval contains_from : string -> int -> char -> bool
Sourceval rcontains_from : string -> int -> char -> bool
Sourceval uppercase : string -> string
  • deprecated Use String.uppercase_ascii instead.
Sourceval lowercase : string -> string
  • deprecated Use String.lowercase_ascii instead.
Sourceval capitalize : string -> string
  • deprecated Use String.capitalize_ascii instead.
Sourceval uncapitalize : string -> string
  • deprecated Use String.uncapitalize_ascii instead.
Sourcetype t = string
Sourceval compare : t -> t -> int
Sourceval equal : t -> t -> bool
Sourceval to_seq : t -> char Seq.t

*_seq functions were introduced in OCaml 4.07.0, and are _not_ implemented in extlib for older OCaml versions

Sourceval to_seqi : t -> (int * char) Seq.t
Sourceval of_seq : char Seq.t -> t