\HeaderA{lcSuffix}{Compute the longest common prefix or suffix of a string}{lcSuffix}
\aliasA{lcPrefix}{lcSuffix}{lcPrefix}
\aliasA{lcPrefixC}{lcSuffix}{lcPrefixC}
\keyword{manip}{lcSuffix}
\begin{Description}\relax
These functions find the longest common prefix or suffix among the
strings in a character vector.
\end{Description}
\begin{Usage}
\begin{verbatim}
lcPrefix(x, ignore.case=FALSE)
lcPrefixC(x, ignore.case=FALSE)
lcSuffix(x, ignore.case=FALSE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a character vector. 
\item[\code{ignore.case}] A logical value indicating whether or
not to ignore the case in making comparisons. 
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Computing the longest common suffix is helpful for truncating names of
objects, like microarrays, that often have a common suffix, such as .CEL.

There are some potential problems with the approach used if
multibyte character encodings are being used.

\code{lcPrefixC} is a faster implementation in C.  It only handles
ascii characters.
\end{Details}
\begin{Value}
The common prefix or suffix.
\end{Value}
\begin{Author}\relax
R. Gentleman
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{nchar}{nchar}}, \code{\LinkA{nchar}{nchar}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
s1 <- c("ABC.CEL", "DEF.CEL")
lcSuffix(s1)

s2 <- c("ABC.123", "ABC.456")
lcPrefix(s2)

CHK <- stopifnot

CHK(".CEL" == lcSuffix(s1))
CHK("bc" == lcSuffix(c("abc", "333abc", "bc")))
CHK("c" == lcSuffix(c("c", "abc", "xxxc")))
CHK("" == lcSuffix(c("c", "abc", "xxx")))

CHK("ABC." == lcPrefix(s2))
CHK("ab" == lcPrefix(c("abcd", "abcd123", "ab", "abc", "abc333333")))
CHK("a" == lcPrefix(c("abcd", "abcd123", "ax")))
CHK("a" == lcPrefix(c("a", "abcd123", "ax")))
CHK("" == lcPrefix(c("a", "abc", "xxx")))

CHK("ab" == lcPrefixC(c("abcd", "abcd123", "ab", "abc", "abc333333")))
CHK("a" == lcPrefixC(c("abcd", "abcd123", "ax")))
CHK("a" == lcPrefixC(c("a", "abcd123", "ax")))
CHK("" == lcPrefixC(c("a", "abc", "xxx")))

\end{ExampleCode}
\end{Examples}

