\Header{substr}{Substrings of a Character Vector}
\alias{substr<\Rdash}{substr}
\alias{substring}{substr}
\alias{substring<\Rdash}{substr}
\keyword{character}{substr}
\begin{Description}\relax
Extract or replace substrings in a character vector.\end{Description}
\begin{Usage}
\begin{verbatim}
substr(x, start, stop)
substring(text, first, last = 1000000)
substr(x, start, stop) <- value
substring(text, first, last = 1000000) <- value
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x, text}] a character vector
\item[\code{start, first}] integer. The first element to be replaced.
\item[\code{stop, last}] integer. The last element to be replaced.
\item[\code{value}] a character vector, recycled if necessary.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{substring} is compatible with S, with \code{first} and
\code{last} instead of \code{start} and \code{stop}.
For vector arguments, it expands the arguments cyclically to the
length of the longest.

When extracting, if \code{start} is larger than the string length then
\code{""} is returned.

For the replacement functions, if \code{start} is larger than the
string length then no replacement is done.  If the portion to be
replaced is longer than the replacement string, then only the
portion the length of the string is replaced.\end{Details}
\begin{Value}
For \code{substr}, a character vector of the same length as \code{x}.

For \code{substring}, a character vector of length the longest of the
arguments.\end{Value}
\begin{Note}\relax
The S4 version of \code{substring<-} ignores \code{last}; this version
does not.\end{Note}
\begin{SeeAlso}\relax
\code{\Link{strsplit}}, \code{\Link{paste}}, \code{\Link{nchar}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
substr("abcdef",2,4)
print(ss <- substring("abcdef",1:6,1:6))
stopifnot(ss == strsplit ("abcdef",NULL)[[1]])
## strsplit is more efficient ...

substr(rep("abcdef",4),1:4,4:5)
x <- c("asfef", "qwerty", "yuiop[", "b", "stuff.blah.yech")
stopifnot(substr(x, 2, 5) == substring(x, 2, 5))
substr(x, 2, 5)
substring(x, 2, 4:6)

substring(x, 2) <- c("..", "+++")
x
\end{ExampleCode}
\end{Examples}

