substr(x, start, stop) substring(text, first, last = 1000000)
start
up to the character at position
stop
.start
is larger than the string length then
NA
is returned.
If stop
is longer than start
an error is signalled.
substring
is compatible with S, with first
and
last
instead of start
and stop
.
For vector arguments, it expands the arguments cyclically.
strsplit
, paste
, nchar
.substr("abcdef",2,4) print(ss <- substring("abcdef",1:6,1:6)) all( 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") all(substr(x, 2, 5) == substring(x, 2, 5)) #> TRUE substr(x, 2, 5) substring(x, 2, 4:6)