Javascript String startsWith(prefix)
String.prototype.startsWith = function(prefix){ if(prefix.length > this.length) return false; for(var i = 0; i < prefix.length; i++) if(prefix[i] != this[i]) return false; return true;//from ww w . jav a 2 s . co m }
String.prototype.startsWith = function (prefix) { return this.indexOf(prefix) === 0; } String.prototype.endsWith = function (suffix) { return this.match(suffix + "$") == suffix; };
String.prototype.startsWith = function(prefix){ return !this.indexOf(prefix); };
String.prototype.startsWith = function (prefix) { "use strict";//from w w w . j av a 2 s. c o m if (!prefix && typeof prefix !== 'string') { return false; } return this.indexOf(prefix) === 0; };
String.prototype.startsWith = function(prefix) { return (this.substr(0, prefix.length) === prefix); };
/**// w ww. ja v a 2s . c o m * see if a string begins with a given string * * Once ecmascript adds this natively, you should build core.js without this method: * @link http://wiki.ecmascript.org/doku.php?id=harmony%3astring_extras * @function external:String.prototype.startsWith * @param {string} A substring expected to be in the beginning of this string * @return {boolean} * @example * 'some string'.startsWith('s') === true; */ String.prototype.startsWith = function (prefix){ return this.slice(0, prefix.length) === prefix; };
/**/*from w w w . jav a 2 s . c o m*/ * see if a string begins with a given string * * Once ecmascript adds this natively, you should build core.js without this method: * @see {@link http://wiki.ecmascript.org/doku.php?id=harmony%3astring_extras Harmony String Extras} * @function module:String.prototype.startsWith * @param {string} A substring expected to be in the beginning of this string * @return {boolean} * @example * 'some string'.startsWith('s') === true; */ String.prototype.startsWith = String.prototype.startsWith || function (prefix){ return this.slice(0, prefix.length) === prefix; };
var DBG = false;// w ww . j a v a 2s . c om String.prototype.startsWith = function(prefix) { return this.indexOf(prefix) === 0; } String.prototype.endsWith = function(suffix) { return this.match(suffix+"$") == suffix; };