indexOf.String: Gets the first position of a character or a substring

Description Usage Arguments Value Author(s) See Also Examples

Description

Gets the first position of the character or the substring s starting from fromIndex.

Usage

1
2
## S3 method for class 'String'
indexOf(this, s, fromIndex=0, ...)

Arguments

fromIndex

The index to start the search from.

Value

Returns the position. If no such character exists, -1 is returned.

Author(s)

Henrik Bengtsson (http://www.braju.com/R/)

See Also

*lastIndexOf(), *charAt()

Examples

1
2
3
4
5
6
  s <- String("Hello world!")
  indexOf(s, "l")               #  2
  indexOf(s, "l", fromIndex=5)  #  9
  indexOf(s, "world")           #  6
  indexOf(s, "a")               # -1
  indexOf("Hello world!", "l")  #  2

HenrikBengtsson/R.lang documentation built on May 8, 2019, 7:50 p.m.