Learn R Programming

cwhmisc (version 2.1)

cpos: Find the position of a substring

Description

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

Usage

cpos(str,sub,start=1)
substring.location(str, sub, restrict)

Arguments

str
string (1-dim)
sub
string (1-dim)
start
integer
restrict
vector of lower and upper index the search should be restricted to

Value

  • number, if found, NA otherwise. list(first,last)

Examples

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

Run the code above in your browser using DataLab