Python endswith() with multiple string

endswith() accepts a tuple of suffixes. You can either convert your list to a tuple or just use a tuple in the first place instead of list. In [1]: sample_str = “Chicago Blackhawks vs. New York Rangers” In [2]: suffixes = (“Toronto Maple Leafs”, “New York Rangers”) In [3]: sample_str.endswith(suffixes) Out[3]: True From doc: str.endswith(suffix[, …

Read more

Xpath “ends-with” does not work

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’

Find out if string ends with another string in C++

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

UPDATE (Nov 24th, 2015): This answer is originally posted in the year 2010 (SIX years back.) so please take note of these insightful comments: Shauna – Update for Googlers – Looks like ECMA6 adds this function. The MDN article also shows a polyfill. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith T.J. Crowder – Creating substrings isn’t expensive on modern browsers; it …

Read more