String.prototype.startsWith = function(str)
{return (this.match("^"+str)==str)}
String.prototype.endsWith = function(str)
{return (this.match(str+"$")==str)}
String.prototype.trim = function(){return
(this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))}
var s = " Real's HowTo ";
var sTrimmed = s.trim(); // =="Real's HowTo"
if (sTrimmed.startsWith("Real")) // returns TRUE
if (sTrimmed.endsWith("HowTo")) // returns TRUE
if (s.startsWith("Real")) // returns FALSE due to the leading spaces
if (s.endsWith("HowTo")) // returns FALSE due to trailing spaces
Written and compiled by Réal Gagnon ©1998-2012
[ home ]