Loudtalks — internet walkie talkie

It's all about passion

We develop custom software for small businesses and entrepreneurs and we do it with passion. What does it mean? We care about what we do. We treat our customers' projects as if they were ours. We deliver personal service and always do our best to offer more value and be more efficient. We innovate. We rely on bright people rather than on formal procedures. It's all about passion, passion about making the best software in the world in the most efficient way.
Metalink's primary focus is:
Our customers list includes start-ups and small businesses from USA, Australia, England, China and Singapore. If you are looking for fast and iterative development performed by young, innovative and mobile team then you are on the right page.
Alexander Vinogradov
Alexander Vinogradov
Senior software developer / Architect
Alexander is “can do” developer. He joined Metalink as Windows C++ developer in January 2003. His strongest virtue is the learning curve… its absence to be precise. He gets familiar with new technologies, tools and programming languages almost instantly and can deliver working product as soon as humanly possible. Alexander holds BSc degree in information security from St ...
More people

trim() function for ActionScript and JavaScript

By Alexey Gavrilov on February 7, 2010

Strangely ActionScript doesn’t have trim() function, JavaScript doesn’t have it either.

I needed the one lately and googled it but a few solutions that came up looked weird (using several for() cycles for example). So I came up with this one — if you know how to make it simpler or shorter, l’d be very interested to hear your solution.

Old school style:


function trim(s) {
    return s.match(/^s*(.*?)s*$/)[1];
}

var s = trim(" well done   "); // s = "well done"
 

Modern style:


String.prototype.trim = function() {
    return this.match(/^s*(.*?)s*$/)[1];
}

var s = "   even better  ".trim(); // s = "even better"
 

Enjoy!

(categories: Technology, Solutions box)