cpos: Find the position of a substring

Description Usage Arguments Value Note Author(s) Examples

Description

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

Usage

1
2
3
4
cpos(str,sub,start=1)
cposV(vstr,sub,vstart=1)
cposR(str, sub, restrict)
issubstr(str,sub,start=1)

Arguments

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.

Value

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.

Note

parameters in cposV will be recycled, so that all have the same (maximum) length.

Author(s)

Christian W. Hoffmann <christian@echoffmann.ch>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
  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")

cwhmisc documentation built on May 1, 2019, 7:55 p.m.