Does R have function startswith or endswith like python?

user4015990 picture user4015990 · Jul 17, 2015 · Viewed 65.6k times · Source
> startsWith('abc', 'a')
[1] TRUE
> startsWith('abc', 'c')
[1] FALSE

> endsWith('abc', 'a')
[1] FALSE  
> endsWith('abc', 'c')
[1] TRUE

Answer

ijoseph picture ijoseph · Jul 1, 2016

As added to base in 3.3.0, startsWith (and endsWith) are exactly this.

> startsWith("what", "wha")
[1] TRUE
> startsWith("what", "ha")
[1] FALSE

https://stat.ethz.ch/R-manual/R-devel/library/base/html/startsWith.html