function trim(str)
    {
        return str.replace(/^\s+|\s+$/g, '');
    }
Removes all white space at the begining and end of a string.

@param {String} str   String to trim.
@return {String}      Returns string without leading and following white space characters.