[Feature request] String starts-with and ends-with
- Dominant language
- C++
- Stars
- 1.6k
- Forks
- 193
- Avg merge
- 1d 33m
- Merged PRs (30d)
- 23
Description
Checking whether a string has a certain prefix or suffix is a common operation, which is why even high-level programming languages have added methods for it when they already had general-purpose substring-finding. (For example, C++ added `.starts_with` and `.ends_with` to `std::string` in C++20, and Javascript added `.startsWith` and `.endsWith` in ECMAScript 2015.)
I commented in #1884 that `^==` and `$==` operators would make sense, in a parallel to regex `^` and `$`, or CSS `^=` and `$=`. But even if it's not a common enough need to warrant operators, functions like `STRSTARTS` and `STRENDS` would also be useful.
Compare:
| Current | Functions | Operators |
| --- | --- | --- |
| `STRFIND("\1", "prefix") == 0` | `STRSTARTS("\1", "prefix")` | `"\1" ^== "prefix"` |
| `STRRFIND("\1", "suffix") == STRLEN("\1") - STRLEN("suffix")` | `STRENDS("\1", "suffix")` | `"\1" $== "suffix"` |
Contributor guide
Assessment
This issue has not been assessed yet.