man-pages/man3/Stdlib.String.3o.html
2021-03-31 01:06:50 +01:00

1319 lines
15 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of Stdlib.String</TITLE>
</HEAD><BODY>
<H1>Stdlib.String</H1>
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
Stdlib.String - no description
<A NAME="lbAC">&nbsp;</A>
<H2>Module</H2>
Module Stdlib.String
<A NAME="lbAD">&nbsp;</A>
<H2>Documentation</H2>
<P>
Module
<B>String</B>
<BR>&nbsp;:&nbsp;
<B>(module Stdlib__string)</B>
<P>
<P>
<P>
<P>
<P>
<P>
<P>
<P>
<I>val length </I>
:
<B>string -&gt; int</B>
<P>
Return the length (number of characters) of the given string.
<P>
<P>
<P>
<I>val get </I>
:
<B>string -&gt; int -&gt; char</B>
<P>
<P>
<B>String.get s n</B>
returns the character at index
<B>n</B>
in string
<B>s</B>
.
You can also write
<B>s.[n]</B>
instead of
<B>String.get s n</B>
.
<P>
Raise
<B>Invalid_argument</B>
if
<B>n</B>
not a valid index in
<B>s</B>
.
<P>
<P>
<P>
<I>val set </I>
:
<B>bytes -&gt; int -&gt; char -&gt; unit</B>
<P>
<B>Deprecated.</B>
This is a deprecated alias of
<B>Bytes.set</B>
.
<B></B>
<P>
<P>
<P>
<B>String.set s n c</B>
modifies byte sequence
<B>s</B>
in place,
replacing the byte at index
<B>n</B>
with
<B>c</B>
.
You can also write
<B>s.[n] &lt;- c</B>
instead of
<B>String.set s n c</B>
.
<P>
Raise
<B>Invalid_argument</B>
if
<B>n</B>
is not a valid index in
<B>s</B>
.
<P>
<P>
<P>
<I>val create </I>
:
<B>int -&gt; bytes</B>
<P>
<B>Deprecated.</B>
This is a deprecated alias of
<B>Bytes.create</B>
.
<B></B>
<P>
<P>
<P>
<B>String.create n</B>
returns a fresh byte sequence of length
<B>n</B>
.
The sequence is uninitialized and contains arbitrary bytes.
<P>
Raise
<B>Invalid_argument</B>
if
<B>n &lt; 0</B>
or
<B>n &gt; </B>
<B>Sys.max_string_length</B>
.
<P>
<P>
<P>
<I>val make </I>
:
<B>int -&gt; char -&gt; string</B>
<P>
<P>
<B>String.make n c</B>
returns a fresh string of length
<B>n</B>
,
filled with the character
<B>c</B>
.
<P>
Raise
<B>Invalid_argument</B>
if
<B>n &lt; 0</B>
or
<B>n &gt; </B>
<B>Sys.max_string_length</B>
.
<P>
<P>
<P>
<I>val init </I>
:
<B>int -&gt; (int -&gt; char) -&gt; string</B>
<P>
<P>
<B>String.init n f</B>
returns a string of length
<B>n</B>
, with character
<B>i</B>
initialized to the result of
<B>f i</B>
(called in increasing
index order).
<P>
Raise
<B>Invalid_argument</B>
if
<B>n &lt; 0</B>
or
<B>n &gt; </B>
<B>Sys.max_string_length</B>
.
<P>
<P>
<B>Since</B>
4.02.0
<P>
<P>
<P>
<I>val copy </I>
:
<B>string -&gt; string</B>
<P>
<B>Deprecated.</B>
Because strings are immutable, it doesn't make much
sense to make identical copies of them.
<P>
<P>
Return a copy of the given string.
<P>
<P>
<P>
<I>val sub </I>
:
<B>string -&gt; int -&gt; int -&gt; string</B>
<P>
<P>
<B>String.sub s start len</B>
returns a fresh string of length
<B>len</B>
,
containing the substring of
<B>s</B>
that starts at position
<B>start</B>
and
has length
<B>len</B>
.
<P>
Raise
<B>Invalid_argument</B>
if
<B>start</B>
and
<B>len</B>
do not
designate a valid substring of
<B>s</B>
.
<P>
<P>
<P>
<I>val fill </I>
:
<B>bytes -&gt; int -&gt; int -&gt; char -&gt; unit</B>
<P>
<B>Deprecated.</B>
This is a deprecated alias of
<B>Bytes.fill</B>
.
<B></B>
<P>
<P>
<P>
<B>String.fill s start len c</B>
modifies byte sequence
<B>s</B>
in place,
replacing
<B>len</B>
bytes with
<B>c</B>
, starting at
<B>start</B>
.
<P>
Raise
<B>Invalid_argument</B>
if
<B>start</B>
and
<B>len</B>
do not
designate a valid range of
<B>s</B>
.
<P>
<P>
<P>
<I>val blit </I>
:
<B>string -&gt; int -&gt; bytes -&gt; int -&gt; int -&gt; unit</B>
<P>
Same as
<B>Bytes.blit_string</B>
.
<P>
<P>
<P>
<I>val concat </I>
:
<B>string -&gt; string list -&gt; string</B>
<P>
<P>
<B>String.concat sep sl</B>
concatenates the list of strings
<B>sl</B>
,
inserting the separator string
<B>sep</B>
between each.
<P>
Raise
<B>Invalid_argument</B>
if the result is longer than
<B>Sys.max_string_length</B>
bytes.
<P>
<P>
<P>
<I>val iter </I>
:
<B>(char -&gt; unit) -&gt; string -&gt; unit</B>
<P>
<P>
<B>String.iter f s</B>
applies function
<B>f</B>
in turn to all
the characters of
<B>s</B>
. It is equivalent to
<B>f s.[0]; f s.[1]; ...; f s.[String.length s - 1]; ()</B>
.
<P>
<P>
<P>
<I>val iteri </I>
:
<B>(int -&gt; char -&gt; unit) -&gt; string -&gt; unit</B>
<P>
Same as
<B>String.iter</B>
, but the
function is applied to the index of the element as first argument
(counting from 0), and the character itself as second argument.
<P>
<P>
<B>Since</B>
4.00.0
<P>
<P>
<P>
<I>val map </I>
:
<B>(char -&gt; char) -&gt; string -&gt; string</B>
<P>
<P>
<B>String.map f s</B>
applies function
<B>f</B>
in turn to all the
characters of
<B>s</B>
(in increasing index order) and stores the
results in a new string that is returned.
<P>
<P>
<B>Since</B>
4.00.0
<P>
<P>
<P>
<I>val mapi </I>
:
<B>(int -&gt; char -&gt; char) -&gt; string -&gt; string</B>
<P>
<P>
<B>String.mapi f s</B>
calls
<B>f</B>
with each character of
<B>s</B>
and its
index (in increasing index order) and stores the results in a new
string that is returned.
<P>
<P>
<B>Since</B>
4.02.0
<P>
<P>
<P>
<I>val trim </I>
:
<B>string -&gt; string</B>
<P>
Return a copy of the argument, without leading and trailing
whitespace. The characters regarded as whitespace are:
<B>' '</B>
,
<B>'\012'</B>
,
<B>'\n'</B>
,
<B>'\r'</B>
, and
<B>'\t'</B>
. If there is neither leading nor
trailing whitespace character in the argument, return the original
string itself, not a copy.
<P>
<P>
<B>Since</B>
4.00.0
<P>
<P>
<P>
<I>val escaped </I>
:
<B>string -&gt; string</B>
<P>
Return a copy of the argument, with special characters
represented by escape sequences, following the lexical
conventions of OCaml.
All characters outside the ASCII printable range (32..126) are
escaped, as well as backslash and double-quote.
<P>
If there is no special character in the argument that needs
escaping, return the original string itself, not a copy.
<P>
Raise
<B>Invalid_argument</B>
if the result is longer than
<B>Sys.max_string_length</B>
bytes.
<P>
The function
<B>Scanf.unescaped</B>
is a left inverse of
<B>escaped</B>
,
i.e.
<B>Scanf.unescaped (escaped s) = s</B>
for any string
<B>s</B>
(unless
<B>escape s</B>
fails).
<P>
<P>
<P>
<I>val index </I>
:
<B>string -&gt; char -&gt; int</B>
<P>
<P>
<B>String.index s c</B>
returns the index of the first
occurrence of character
<B>c</B>
in string
<B>s</B>
.
<P>
Raise
<B>Not_found</B>
if
<B>c</B>
does not occur in
<B>s</B>
.
<P>
<P>
<P>
<I>val index_opt </I>
:
<B>string -&gt; char -&gt; int option</B>
<P>
<P>
<B>String.index_opt s c</B>
returns the index of the first
occurrence of character
<B>c</B>
in string
<B>s</B>
, or
<B>None</B>
if
<B>c</B>
does not occur in
<B>s</B>
.
<P>
<P>
<B>Since</B>
4.05
<P>
<P>
<P>
<I>val rindex </I>
:
<B>string -&gt; char -&gt; int</B>
<P>
<P>
<B>String.rindex s c</B>
returns the index of the last
occurrence of character
<B>c</B>
in string
<B>s</B>
.
<P>
Raise
<B>Not_found</B>
if
<B>c</B>
does not occur in
<B>s</B>
.
<P>
<P>
<P>
<I>val rindex_opt </I>
:
<B>string -&gt; char -&gt; int option</B>
<P>
<P>
<B>String.rindex_opt s c</B>
returns the index of the last occurrence
of character
<B>c</B>
in string
<B>s</B>
, or
<B>None</B>
if
<B>c</B>
does not occur in
<B>s</B>
.
<P>
<P>
<B>Since</B>
4.05
<P>
<P>
<P>
<I>val index_from </I>
:
<B>string -&gt; int -&gt; char -&gt; int</B>
<P>
<P>
<B>String.index_from s i c</B>
returns the index of the
first occurrence of character
<B>c</B>
in string
<B>s</B>
after position
<B>i</B>
.
<B>String.index s c</B>
is equivalent to
<B>String.index_from s 0 c</B>
.
<P>
Raise
<B>Invalid_argument</B>
if
<B>i</B>
is not a valid position in
<B>s</B>
.
Raise
<B>Not_found</B>
if
<B>c</B>
does not occur in
<B>s</B>
after position
<B>i</B>
.
<P>
<P>
<P>
<I>val index_from_opt </I>
:
<B>string -&gt; int -&gt; char -&gt; int option</B>
<P>
<P>
<B>String.index_from_opt s i c</B>
returns the index of the
first occurrence of character
<B>c</B>
in string
<B>s</B>
after position
<B>i</B>
or
<B>None</B>
if
<B>c</B>
does not occur in
<B>s</B>
after position
<B>i</B>
.
<P>
<P>
<B>String.index_opt s c</B>
is equivalent to
<B>String.index_from_opt s 0 c</B>
.
Raise
<B>Invalid_argument</B>
if
<B>i</B>
is not a valid position in
<B>s</B>
.
<P>
<P>
<B>Since</B>
4.05
<P>
<P>
<P>
<I>val rindex_from </I>
:
<B>string -&gt; int -&gt; char -&gt; int</B>
<P>
<P>
<B>String.rindex_from s i c</B>
returns the index of the
last occurrence of character
<B>c</B>
in string
<B>s</B>
before position
<B>i+1</B>
.
<B>String.rindex s c</B>
is equivalent to
<B>String.rindex_from s (String.length s - 1) c</B>
.
<P>
Raise
<B>Invalid_argument</B>
if
<B>i+1</B>
is not a valid position in
<B>s</B>
.
Raise
<B>Not_found</B>
if
<B>c</B>
does not occur in
<B>s</B>
before position
<B>i+1</B>
.
<P>
<P>
<P>
<I>val rindex_from_opt </I>
:
<B>string -&gt; int -&gt; char -&gt; int option</B>
<P>
<P>
<B>String.rindex_from_opt s i c</B>
returns the index of the
last occurrence of character
<B>c</B>
in string
<B>s</B>
before position
<B>i+1</B>
or
<B>None</B>
if
<B>c</B>
does not occur in
<B>s</B>
before position
<B>i+1</B>
.
<P>
<P>
<B>String.rindex_opt s c</B>
is equivalent to
<B>String.rindex_from_opt s (String.length s - 1) c</B>
.
<P>
Raise
<B>Invalid_argument</B>
if
<B>i+1</B>
is not a valid position in
<B>s</B>
.
<P>
<P>
<B>Since</B>
4.05
<P>
<P>
<P>
<I>val contains </I>
:
<B>string -&gt; char -&gt; bool</B>
<P>
<P>
<B>String.contains s c</B>
tests if character
<B>c</B>
appears in the string
<B>s</B>
.
<P>
<P>
<P>
<I>val contains_from </I>
:
<B>string -&gt; int -&gt; char -&gt; bool</B>
<P>
<P>
<B>String.contains_from s start c</B>
tests if character
<B>c</B>
appears in
<B>s</B>
after position
<B>start</B>
.
<B>String.contains s c</B>
is equivalent to
<B>String.contains_from s 0 c</B>
.
<P>
Raise
<B>Invalid_argument</B>
if
<B>start</B>
is not a valid position in
<B>s</B>
.
<P>
<P>
<P>
<I>val rcontains_from </I>
:
<B>string -&gt; int -&gt; char -&gt; bool</B>
<P>
<P>
<B>String.rcontains_from s stop c</B>
tests if character
<B>c</B>
appears in
<B>s</B>
before position
<B>stop+1</B>
.
<P>
Raise
<B>Invalid_argument</B>
if
<B>stop &lt; 0</B>
or
<B>stop+1</B>
is not a valid
position in
<B>s</B>
.
<P>
<P>
<P>
<I>val uppercase </I>
:
<B>string -&gt; string</B>
<P>
<B>Deprecated.</B>
Functions operating on Latin-1 character set are deprecated.
<P>
<P>
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.
<P>
<P>
<P>
<I>val lowercase </I>
:
<B>string -&gt; string</B>
<P>
<B>Deprecated.</B>
Functions operating on Latin-1 character set are deprecated.
<P>
<P>
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.
<P>
<P>
<P>
<I>val capitalize </I>
:
<B>string -&gt; string</B>
<P>
<B>Deprecated.</B>
Functions operating on Latin-1 character set are deprecated.
<P>
<P>
Return a copy of the argument, with the first character set to uppercase,
using the ISO Latin-1 (8859-1) character set..
<P>
<P>
<P>
<I>val uncapitalize </I>
:
<B>string -&gt; string</B>
<P>
<B>Deprecated.</B>
Functions operating on Latin-1 character set are deprecated.
<P>
<P>
Return a copy of the argument, with the first character set to lowercase,
using the ISO Latin-1 (8859-1) character set..
<P>
<P>
<P>
<I>val uppercase_ascii </I>
:
<B>string -&gt; string</B>
<P>
Return a copy of the argument, with all lowercase letters
translated to uppercase, using the US-ASCII character set.
<P>
<P>
<B>Since</B>
4.03.0
<P>
<P>
<P>
<I>val lowercase_ascii </I>
:
<B>string -&gt; string</B>
<P>
Return a copy of the argument, with all uppercase letters
translated to lowercase, using the US-ASCII character set.
<P>
<P>
<B>Since</B>
4.03.0
<P>
<P>
<P>
<I>val capitalize_ascii </I>
:
<B>string -&gt; string</B>
<P>
Return a copy of the argument, with the first character set to uppercase,
using the US-ASCII character set.
<P>
<P>
<B>Since</B>
4.03.0
<P>
<P>
<P>
<I>val uncapitalize_ascii </I>
:
<B>string -&gt; string</B>
<P>
Return a copy of the argument, with the first character set to lowercase,
using the US-ASCII character set.
<P>
<P>
<B>Since</B>
4.03.0
<P>
<P>
<I>type t </I>
=
<B>string</B>
<P>
<P>
An alias for the type of strings.
<P>
<P>
<P>
<I>val compare </I>
:
<B>t -&gt; t -&gt; int</B>
<P>
The comparison function for strings, with the same specification as
<B>compare</B>
. Along with the type
<B>t</B>
, this function
<B>compare</B>
allows the module
<B>String</B>
to be passed as argument to the functors
<B>Set.Make</B>
and
<B>Map.Make</B>
.
<P>
<P>
<P>
<I>val equal </I>
:
<B>t -&gt; t -&gt; bool</B>
<P>
The equal function for strings.
<P>
<P>
<B>Since</B>
4.03.0
<P>
<P>
<P>
<I>val split_on_char </I>
:
<B>char -&gt; string -&gt; string list</B>
<P>
<P>
<B>String.split_on_char sep s</B>
returns the list of all (possibly empty)
substrings of
<B>s</B>
that are delimited by the
<B>sep</B>
character.
<P>
The function's output is specified by the following invariants:
<P>
<P>
-The list is not empty.
<P>
-Concatenating its elements using
<B>sep</B>
as a separator returns a
string equal to the input (
<B>String.concat (String.make 1 sep)</B>
<B>(String.split_on_char sep s) = s</B>
).
<P>
-No string in the result contains the
<B>sep</B>
character.
<P>
<P>
<P>
<B>Since</B>
4.04.0
<P>
<P>
<P>
<P>
<A NAME="lbAE">&nbsp;</A>
<H3>Iterators</H3>
<P>
<P>
<P>
<I>val to_seq </I>
:
<B>t -&gt; char Seq.t</B>
<P>
Iterate on the string, in increasing index order. Modifications of the
string during iteration will be reflected in the iterator.
<P>
<P>
<B>Since</B>
4.07
<P>
<P>
<P>
<I>val to_seqi </I>
:
<B>t -&gt; (int * char) Seq.t</B>
<P>
Iterate on the string, in increasing order, yielding indices along chars
<P>
<P>
<B>Since</B>
4.07
<P>
<P>
<P>
<I>val of_seq </I>
:
<B>char Seq.t -&gt; t</B>
<P>
Create a string from the generator
<P>
<P>
<B>Since</B>
4.07
<P>
<P>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">Module</A><DD>
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
<DL>
<DT id="4"><A HREF="#lbAE">Iterators</A><DD>
</DL>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:57 GMT, March 31, 2021
</BODY>
</HTML>