On May 5, 2011, at 4:55 PM, Worik R wrote:

Friends

This is an elementary question.  Is there is a built in R function for
finding a sub-string in another string?  Like strstr in C.

I can easily roll my own, but if there is a built in that is one less thing
I can do wrong!

I have no acquaintance with that function, but perhaps:

?grep

regexpr :
"returns an integer vector of the same length as text giving the starting position of the first match or -1 if there is none, ..."

> tst <- "abcde"; regexpr("bc", tst)
[1] 2
attr(,"match.length")
[1] 2


--

David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to