Javascript String startWith(str)
String.prototype.startWith = function(str) { var reg = new RegExp("^" + str); return reg.test(this); };
String.prototype.startWith = function(str){ return this.indexOf(str) == 0; };
String.prototype.startWith=function(str){ if(str==null||str==""||this.length==0||str.length>this.length) return false; if(this.substr(0,str.length)==str) return true; else/*from w w w . j ava 2s. c o m*/ return false; return true; }
String.prototype.startWith = function(str) { var result = true; if (typeof(str)=='string' && str.length <= this.length) { for (var i=0,len=str.length;i<len;i++) { if (str.charAt(i) == this.charAt(i)) { continue;//from w ww .ja va 2 s . c om } else { result = false; break; } } } else { result = false; } return result; }
String.prototype.startWith = function(str) { return (this.match("^" + RegExp.escape(str))==str); }