Standard Module string

string This module defines some constants useful for checking character classes and some useful string functions. See the modules regex and regsub for string functions based on regular expressions. The constants defined in this module are are:
\begin{datadesc}{digits}
 The string \code{'0123456789'}.
\end{datadesc}

\begin{datadesc}{hexdigits}
 The string \code{'0123456789abcdefABCDEF'}.
\end{datadesc}

\begin{datadesc}{letters}
 The concatenation of the strings \code{lowercase} and
 \code{uppercase} described below.
\end{datadesc}

\begin{datadesc}{lowercase}
 A string containing all the characters that are con...
...t on the routines \code{upper} and \code{swapcase} is
 undefined.
\end{datadesc}

\begin{datadesc}{octdigits}
 The string \code{'01234567'}.
\end{datadesc}

\begin{datadesc}{uppercase}
 A string containing all the characters that are con...
...t on the routines \code{lower} and \code{swapcase} is
 undefined.
\end{datadesc}

\begin{datadesc}{whitespace}
 A string containing all characters that are consid...
...fect on the routines \code{strip} and \code{split} is
 undefined.
\end{datadesc}
The functions defined in this module are:
\begin{funcdesc}{atof}{s}
Convert a string to a floating point number. The strin...
... in Python, optionally
preceded by a sign (\samp{+} or \samp{-}).
\end{funcdesc}

\begin{funcdesc}{atoi}{s\optional{\, base}}
Convert string \var{s} to an integer...
...als, use the built-in function
\code{eval()}.)
\bifuncindex{eval}
\end{funcdesc}

\begin{funcdesc}{atol}{s\optional{\, base}}
Convert string \var{s} to a long int...
...or \code{atoi()}. A trailing \samp{l} or \samp{L} is not
allowed.
\end{funcdesc}

\begin{funcdesc}{expandtabs}{s\, tabsize}
Expand tabs in a string, i.e.\ replace...
...n't understand other non-printing characters or escape
sequences.
\end{funcdesc}

\begin{funcdesc}{find}{s\, sub\optional{\, start}}
Return the lowest index in \v...
...ode{0}. If \var{start} is
negative, \code{len(\var{s})} is added.
\end{funcdesc}

\begin{funcdesc}{rfind}{s\, sub\optional{\, start}}
Like \code{find} but find the highest index.
\end{funcdesc}

\begin{funcdesc}{index}{s\, sub\optional{\, start}}
Like \code{find} but raise \code{ValueError} when the substring is
not found.
\end{funcdesc}

\begin{funcdesc}{rindex}{s\, sub\optional{\, start}}
Like \code{rfind} but raise \code{ValueError} when the substring is
not found.
\end{funcdesc}

\begin{funcdesc}{count}{s\, sub\optional{\, start}}
Return the number of (non-ov...
...ode{0}. If \var{start} is
negative, \code{len(\var{s})} is added.
\end{funcdesc}

\begin{funcdesc}{lower}{s}
Convert letters to lower case.
\end{funcdesc}

\begin{funcdesc}{split}{s}
Return a list of the whitespace-delimited words of the string
\var{s}.
\end{funcdesc}

\begin{funcdesc}{splitfields}{s\, sep}
 Return a list containing the fields of t...
...{s}]}, for any string
 \var{s}. (See also \code{regsub.split()}.)
\end{funcdesc}

\begin{funcdesc}{join}{words}
Concatenate a list or tuple of words with intervening spaces.
\end{funcdesc}

\begin{funcdesc}{joinfields}{words\, sep}
Concatenate a list or tuple of words w...
...ring.splitfields(\var{t}, \var{sep}), \var{sep})}
equals \var{t}.
\end{funcdesc}

\begin{funcdesc}{strip}{s}
Remove leading and trailing whitespace from the string
\var{s}.
\end{funcdesc}

\begin{funcdesc}{swapcase}{s}
Convert lower case letters to upper case and vice versa.
\end{funcdesc}

\begin{funcdesc}{translate}{s, table}
Translate the characters from \var{s} usin...
...the translation for each character
value, indexed by its ordinal.
\end{funcdesc}

\begin{funcdesc}{upper}{s}
Convert letters to upper case.
\end{funcdesc}

\begin{funcdesc}{ljust}{s\, width}
\funcline{rjust}{s\, width}
\funcline{center}...
... on the right, left or both sides.
The string is never truncated.
\end{funcdesc}

\begin{funcdesc}{zfill}{s\, width}
Pad a numeric string on the left with zero di...
...h is reached. Strings starting with a sign are handled correctly.
\end{funcdesc}
This module is implemented in Python. Much of its functionality has been reimplemented in the built-in module strop. However, you should never import the latter module directly. When string discovers that strop exists, it transparently replaces parts of itself with the implementation from strop. After initialization, there is no overhead in using string instead of strop. strop