ends-with

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

穿精又带淫゛_ 提交于 2019-11-26 05:19:58
问题 How can I find out if a string ends with another string in C++? 回答1: 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 =

Xpath “ends-with” does not work

雨燕双飞 提交于 2019-11-26 04:48:57
问题 I am trying to find an input element with dynamic id name always ending with \"register\". So far I tried this \"//input[@id[ends-with(.,\'register\')]]\" and this \"//input[ends-with(@id,\'register\')]\" none of these result in an element. What am I doing wrong? At the same time this works: \"//input[@id[contains(.,\'register\')]]\" Here\'s the part of source: <td class=\"input\"> <input id=\"m.f0.menu.f2.volumeTabs.BLOCK_COMMON.tcw.form.register\" name=\"m.f0.menu.f2.volumeTabs.BLOCK_COMMON

endsWith in JavaScript

拥有回忆 提交于 2019-11-26 01:23:01
问题 How can I check if a string ends with a particular character in JavaScript? Example: I have a string var str = \"mystring#\"; I want to know if that string is ending with # . How can I check it? Is there a endsWith() method in JavaScript? One solution I have is take the length of the string and get the last character and check it. Is this the best way or there is any other way? 回答1: UPDATE (Nov 24th, 2015): This answer is originally posted in the year 2010 (SIX years back.) so please take