Thursday, July 2, 2009

startsWith and endsWith functions in Javascript

inside script tag,

var data = "Helloo Good Morning";
startsWith
String.prototype.startsWith = function(data)
{
return (this.match("^"+data)==data)
}

eg:
data.startsWith("Helloo");
returns true
-----------------------------------------------------------------------
endsWith
String.prototype.endsWith = function(data)
{
return (this.match(data+"$")==data)
}
eg:
data.endsWith("Helloo");
returns false;

----------------------------------------------------------
trim
String.prototype.trim = function()
{
return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))
}
eg:
var tm = data.trim();


for more ...
http://www.tek-tips.com

1 comment:

Anonymous said...

Hello nice one. really useful information