XPath testing that string ends with substring?
XPath 2.0 //div[ends-with(@tagname, ‘Destination’)] XPath 1.0 //div[substring(@tagname, string-length(@tagname) – string-length(‘Destination’) + 1) = ‘Destination’]
XPath 2.0 //div[ends-with(@tagname, ‘Destination’)] XPath 1.0 //div[substring(@tagname, string-length(@tagname) – string-length(‘Destination’) + 1) = ‘Destination’]
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
The ends-with function is part of xpath 2.0 but browsers (you indicate you’re testing with chrome) generally only support 1.0. So you’ll have to implement it yourself with a combination of string-length, substring and equals substring(@id, string-length(@id) – string-length(‘register’) +1) = ‘register’
Simply compare the last n characters using std::string::compare: #include <iostream> bool hasEnding (std::string const &fullString, std::string const &ending) { if (fullString.length() >= ending.length()) { return (0 == fullString.compare (fullString.length() – ending.length(), ending.length(), ending)); } else { return false; } } int main () { std::string test1 = “binary”; std::string test2 = “unary”; std::string test3 = … Read more
endsWith in JavaScript