substituteString(pattern, replacement, x, ignore.case=FALSE, extended=TRUE, perl=FALSE, global=FALSE, fixed=FALSE)
gsub(pattern, replacement, x, ignore.case=FALSE, extended=TRUE, perl=FALSE, fixed=FALSE)
sub(pattern, replacement, x, ignore.case=FALSE, extended=TRUE, perl=FALSE, fixed=FALSE)
regexpr().
x matching the pattern.
If
fixed is not
TRUE,
then you may use
"\\n" in the replacement
string (where n is a digit) to mean to insert the n'th parenthesized subpattern here.
Because the backslash may have a special meaning in replacements
when
fixed is
FALSE,
you must use 2 backslashes to put a backslash in the replacement.
(Because Spotfire S+ uses 2 backslashes to represent 1 backslash, that means
you must type 4 backslashes.)
TRUE then the case (upper or lower)
of alphabetic characters is ignored so that, e.g., the pattern
"A" matches both
"a"
and
"A".
TRUE the pattern is taken to be an
extended regular expression. Otherwise it is interpreted as
an obsolete regular expression. See the help file
for
regexpr
for details.
FALSE.
FALSE only the first match of
pattern
in
x will be replaced. If
TRUE then
all matches will be replaced.
TRUE the pattern is not interpreted
as a regular expression, but as a string with no special characters
in it. In this case the
extended and
perl are taken to be
FALSE,
but the
ignore.case is respected.
x.
For compatibility with R, the
gsub and
sub
functions
are the same as
substituteString with
global=TRUE
and
global=FALSE,
respectively.
Versions of S-PLUS prior to 8.0 had a
sub
function for subscripting 2 dimensional objects. It has been renamed
subscript2d
.
# Remove possible .xls suffix, any case
substituteString("\\.xls$", "", c("Data.XLS", "Odd.xls.XLS"), ignore.case=TRUE)
# [1] "Data" "Odd.xls"
substituteString("man", "MAN", "A man, another man, and a woman", global=TRUE)
# [1] "A MAN, another MAN, and a woMAN"
gsub("([-+]?[0-9]+)", "<INTEGER:\\1>", "10 packs of 6")
# [1] "<INTEGER:10> packs of <INTEGER:6>"
cat(gsub("[\\/]", "\\\\", "C:/PROGRAM FILES/TIBCO/splus81\\library\\bigdata"), "\n")
# C:\PROGRAM FILES\TIBCO\splus81\library\bigdata