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" |
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_withand.ends_withtostd::stringin C++20, and Javascript added.startsWithand.endsWithin 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 likeSTRSTARTSandSTRENDSwould also be useful.Compare:
STRFIND("\1", "prefix") == 0STRSTARTS("\1", "prefix")"\1" ^== "prefix"STRRFIND("\1", "suffix") == STRLEN("\1") - STRLEN("suffix")STRENDS("\1", "suffix")"\1" $== "suffix"