Edentity Web Systems
You solve creative. We crack code.
/Header/WhoWeAre.jpg
 

09/15/2009 Useful Javascript functions
Posted by Andre Small

The String.Trim(), String.StartWith and String.EndWith methods are very useful methods that are prebuilt into the .NET framework, that need a client-side implementation. Below are the javascript equivalents that I have found to be extremely helpful.

String.prototype.trim = function(){return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))}

String.prototype.startsWith = function(str) {return (this.match("^"+str)==str)}

String.prototype.endsWith = function(str)  {return (this.match(str+"$")==str)}

Credit: http://www.tek-tips.com/faqs.cfm?fid=6620

Also, The ResolveUrl() method that I (we) use a lot in ASP.NET development. Here is a Javascript equivalent. Note: This requires some help from ASP.NET to provide the resolution of the "~/" and needs to be inline in the HTML.

function ResolveUrl(url) {
 if (url.match("^~/") == "~/") {
  return url.replace("~/", "<%= ResolveUrl("~/") %>");
 }
 
 return url;
}

I hope this helps you.

« Back to Blog Main Page |

0 Comment(s)

Leave Comment

Name:
Comment:  
 
Security Check: 
 
 
Edentity Web Systems Inc.
Suite 201
40 Spadina Ave.
Toronto ON
M5V 2H8
Tel:
416.591.2500
Fax:
416.352.5270
Home | Who We Are | What We Do | Clients & Brands | Careers | Contact

Copyright © 2010 Edentity Web Systems Inc. Privacy Policy