Learn R Programming

cwhmisc (version 6.0)

cpos: Find the position of a substring

Description

cpos finds the first position of a substring cposR returns a list with starting and ending positions, works only with a single string.

Usage

cpos(str,sub,start=1)
cposR(str, sub, restrict)

Arguments

str
string)
sub
string)
start
integer
restrict
vector of lower and upper index the search should be restricted to. If missing, whole str is taken.

Value

  • cpos number, if found, NA otherwise. cposR list(first,last) for each occurrence If there is none of first=NA,last=NA.

Examples

Run this code
cpos("Baldrian","a",5) #  8
cpos("Baldrian","B",15) # NA
cposR("In theese housees there are rats","ees")
#$first  [1]  6 15
#$last   [1]  8 17

Run the code above in your browser using DataLab