EndsWith:
statement.substr( -1 * (searchString.length) ) === searchString;
StartsWith:
statement.substr(0, searchString.length) === searchString;
I could add those to the string.prototype in JavaScript and then reference them the same was I do in C#, too. Like this:
String.prototype.startsWith = function(searchString) {
return this.substr(0, searchString.length) === searchString;
};
String.prototype.endsWith = function(searchString) {
return this.substr(-1 * (searchString.length)) === searchString;
};
statement.startsWith(searchString);
statement.endsWith(searchString);
Neat, huh?!
No comments:
Post a Comment