Find the position of a substring
cpos, cposV
finds the first position of a substring; cposR
returns a list with starting and ending positions, works only with a single string; issubstr
checks if is a substring
cpos(str,sub,start=1) cposV(vstr,sub,vstart=1) cposR(str, sub, restrict) issubstr(str,sub,start=1)
str |
string to examine |
vstr |
vector of strings to examine |
sub |
(vector of) substring to find |
start,vstart |
(vector of) integer, position(s) of start of search |
restrict |
vector of lower and upper index the search should be restricted to. If missing, whole 'str' is taken. |
cpos,cposL,cposV
number, if found, NA otherwise.cposR
list(first,last) for each occurrence of sub
within the restriction restrict
of str
; If there is none, then first
=NA,last
=NA.
parameters in cposV
will be recycled, so that all have the same (maximum) length.
Christian W. Hoffmann <christian@echoffmann.ch>
cpos(" Baldrian","a",5) # 3 cpos("Baldrian","B",15) # NA cposR(" Baldabcrian abcf","abc") #$first 6 15 #$last 8 17 cposR(" Baldabcrian abcf","abc",c(2:16)) #$first 6 #$last 8 cposV(c("Xcdbeesh","withh "),c("X","h","ees"),c(1,5)) # 1 4 5 issubstr("Today is a wonderful day","wonder")
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.